Skip to content

Commit 04aa7d9

Browse files
committed
Add exports to package.json to satisfy nodejs --experimental-module users
Fixes #206 This ensures that consumers using --experimental-modules with node 12+ will import the esm version of this package. This package's export MUST have .mjs file extension... (because otherwise the entire package must be specified as type: module) This package's export MUST use exports field in the package.json see https://nodejs.org/api/packages.html#conditional-exports Not sure how to test this with a bunch of different project styles.. webpack and other loaders _should_ be fine with importing from the `module` field with a `.mjs` file extension?
1 parent cc4f9ae commit 04aa7d9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
],
2121
"main": "dist.es5/index.js",
2222
"module": "dist.es5m/index.js",
23+
"exports": {
24+
"import": "./dist.es5m/index.mjs",
25+
"require": "./dist.es5/index.js"
26+
},
2327
"es2015": "dist.es2015/index.js",
2428
"typings": "dist.es2015/index",
2529
"sideEffects": false,
@@ -28,7 +32,7 @@
2832
"build": "yarn build-modern && yarn build-es5 && yarn build-es5m",
2933
"build-modern": "tsc -p src",
3034
"build-es5": "tsc -p src --target es5 --outDir dist.es5",
31-
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m",
35+
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m; mv index.js index.mjs; mv index.spec.js index.spec.mjs",
3236
"build-watch": "yarn build-es5 -w",
3337
"clean": "rimraf 'dist*'",
3438
"lint": "eslint 'src/*.ts'",

0 commit comments

Comments
 (0)