From 12901c168793b19ca9f5b97042cb94958c4b7ebe Mon Sep 17 00:00:00 2001 From: Jamie Pate Date: Fri, 11 Feb 2022 17:11:45 -0800 Subject: [PATCH] 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 --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c4cec0..c245610 100644 --- a/package.json +++ b/package.json @@ -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, @@ -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'",