From https://nodejs.org/api/esm.html#introduction:
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export statements.
Extension
comes with a default ECMAScript Module template for new projects, which you can use as a starting point for your next ECMAScript Module-based Extension. This is the easiest way to have ECMAScript Modules integrated with Extension
.
To make Extension
recognize all files as ECMAScript Modules, define "type": "module"
in your package.json
.
ECMAScript Modules have some differences from CommonJS modules. See below.
*.js
or *.mjs
).Except for modules imported from your package.json
, all imports must include its file extension.
"default"
export can be imported from non-ESM. Named exports are not available.If the file you are working on is not an ESM but the file you are importing is, then it must use a default import to work.
Attempting to use CommonJS syntax such as require
, module
, exports
, __filename
, __dirname
will result in an error.
Extension
works with extensions using CSS Modules.