Please read /docs/esm for full details & comparisons.
Unlike /examples/esm.loader, this example uses the native ESM loader whenever it's available.
Unlike /examples/esm.mjs, this example will run in all versions of Node.js – including older versions where ESM is not natively supported.
-
Define
"type": "module"
withinpackage.json
Allows Node.js to treat.js
files as ESM. -
Define
import
statements with full file paths
Required by Node.js whenever ESM in use. -
Define two
test
scripts:"test:native"
– for use within Node 12+"test:legacy"
– for use with Node < 12
MIT © Luke Edwards