Skip to content

Commit

Permalink
Add exports to package.json to satisfy nodejs --experimental-module u…
Browse files Browse the repository at this point in the history
…sers

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
  • Loading branch information
jamie-pate committed Feb 14, 2022
1 parent cc4f9ae commit 12901c1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -20,6 +20,10 @@
],
"main": "dist.es5/index.js",
"module": "dist.es5m/index.js",
"exports": {
"import": "./dist.es5m/index.js",
"require": "./dist.es5/index.js"
},
"es2015": "dist.es2015/index.js",
"typings": "dist.es2015/index",
"sideEffects": false,
Expand All @@ -28,7 +32,7 @@
"build": "yarn build-modern && yarn build-es5 && yarn build-es5m",
"build-modern": "tsc -p src",
"build-es5": "tsc -p src --target es5 --outDir dist.es5",
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m",
"build-es5m": "yarn build-es5 -m es2015 --outDir dist.es5m && echo '{\"type\":\"module\"}' > dist.es5m/package.json",
"build-watch": "yarn build-es5 -w",
"clean": "rimraf 'dist*'",
"lint": "eslint 'src/*.ts'",
Expand Down

0 comments on commit 12901c1

Please sign in to comment.