Skip to content

Commit 39a94d1

Browse files
authored
Add exports in to make /native work in Node 16.x ESM modules (#318)
If you're trying to import `react-content-loader/native` from Node 16.x from within a ESM context (`"type": "module"`). You'll get the following error: ``` node:internal/process/esm_loader:97 internalBinding('errors').triggerUncaughtException( ^ Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '~/node_modules/react-content-loader/native' is not supported resolving ES modules imported from /Users/swen/Code/cheetah/test/test.mjs Did you mean to import react-content-loader/native/react-content-loader.native.cjs.js? at new NodeError (node:internal/errors:387:5) at finalizeResolution (node:internal/modules/esm/resolve:425:17) at moduleResolve (node:internal/modules/esm/resolve:1006:10) at defaultResolve (node:internal/modules/esm/resolve:1214:11) at nextResolve (node:internal/modules/esm/loader:165:28) at ESMLoader.resolve (node:internal/modules/esm/loader:844:30) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:431:18) at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40) at link (node:internal/modules/esm/module_job:75:36) { code: 'ERR_UNSUPPORTED_DIR_IMPORT', url: 'file:///~/node_modules/react-content-loader/native' } ``` By setting up an explicit export for the `/native` subdirectory the import works. No other changes are made to maintain backwards compatibility.
1 parent 1f9577c commit 39a94d1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212
"module": "dist/react-content-loader.es.js",
1313
"jsnext:main": "dist/react-content-loader.es.js",
1414
"types": "dist/web/index.d.ts",
15+
"exports": {
16+
".": {
17+
"types": "./dist/web/index.d.ts",
18+
"require": "dist/react-content-loader.cjs.js",
19+
"import": "dist/react-content-loader.es.js",
20+
"default": "dist/react-content-loader.cjs.js"
21+
},
22+
"./native": {
23+
"types": "./native/native/index.d.ts",
24+
"require": "./native/react-content-loader.native.cjs.js",
25+
"import": "./native/react-content-loader.native.es.js",
26+
"default": "./native/react-content-loader.native.cjs.js"
27+
}
28+
},
1529
"bugs": {
1630
"url": "https://github.com/danilowoz/react-content-loader/issues"
1731
},

0 commit comments

Comments
 (0)