Skip to content

Commit 12901c1

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 a package.json with "type": "json" (or module files must have .mjs extension)... This package's export must also use exports field in the package.json because node doesn't support the "module" field as an alternative to "main". see https://nodejs.org/api/packages.html#conditional-exports
1 parent cc4f9ae commit 12901c1

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.js",
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 && echo '{\"type\":\"module\"}' > dist.es5m/package.json",
3236
"build-watch": "yarn build-es5 -w",
3337
"clean": "rimraf 'dist*'",
3438
"lint": "eslint 'src/*.ts'",

0 commit comments

Comments
 (0)