Skip to content

Commit

Permalink
Add exports in to make /native work in Node 16.x ESM modules (#318)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Photonios authored Jun 7, 2024
1 parent 1f9577c commit 39a94d1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
"module": "dist/react-content-loader.es.js",
"jsnext:main": "dist/react-content-loader.es.js",
"types": "dist/web/index.d.ts",
"exports": {
".": {
"types": "./dist/web/index.d.ts",
"require": "dist/react-content-loader.cjs.js",
"import": "dist/react-content-loader.es.js",
"default": "dist/react-content-loader.cjs.js"
},
"./native": {
"types": "./native/native/index.d.ts",
"require": "./native/react-content-loader.native.cjs.js",
"import": "./native/react-content-loader.native.es.js",
"default": "./native/react-content-loader.native.cjs.js"
}
},
"bugs": {
"url": "https://github.com/danilowoz/react-content-loader/issues"
},
Expand Down

0 comments on commit 39a94d1

Please sign in to comment.