Not able to import /async, /creatable, .etc from an ES module
See original GitHub issueMinimal repro
If placed in an .mjs
file, the following code results in an error.
import AsyncSelect from "react-select/async";
console.log(AsyncSelect);
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'C:\Projects\OSS\Bugs\react-select-esm-repro\node_modules\react-select\async' is not supported resolving ES modules imported from C:\Projects\OSS\Bugs\react-select-esm-repro\index.mjs
Did you mean to import react-select-esm-repro/node_modules/react-select/async/dist/react-select.cjs.js?
at finalizeResolution (internal/modules/esm/resolve.js:281:17)
at moduleResolve (internal/modules/esm/resolve.js:708:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:819:11)
at Loader.resolve (internal/modules/esm/loader.js:89:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:73:40)
at link (internal/modules/esm/module_job.js:72:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///C:/Projects/OSS/Bugs/react-select-esm-repro/node_modules/react-select/async'
}
While this reproduction uses Node, the issue also occurs when using Webpack 5 which follows Node’s handling of ES module imports. Here’s the Webpack error for Googleability:
Module not found: Error: Can't resolve 'react-select/async' in 'C:\Projects\ITI\iti-react\iti-react\dist'
Did you mean 'react-select.esm.js'?
BREAKING CHANGE: The request 'react-select/async' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Suggested Solution
Utilize the exports
field in package.json
as described in the Node documentation.
Additional Context
- react-select version: 5.1.0
- Node version: 14.17.6
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top Results From Across the Web
How can I import an ES module in the Node.js REPL in Node 8?
The problem with asynchronous import is solved with node --experimental-repl-await . It's const myModule = await import("./my-module.js") then.
Read more >ES2020: `import()` – dynamically importing ES modules - 2ality
import * as someModule from './dir/someModule. js'; First, this import declaration can only appear at the top level of a module. That prevents ......
Read more >Using ES modules in Node.js - LogRocket Blog
To be able to load an ES module, we need to set “type”: “module” in this file or, as an alternative, we can...
Read more >import - JavaScript - MDN Web Docs - Mozilla
The imported bindings are called live bindings because they are updated by the module that exported the binding, but cannot be modified by...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
CJS Can import() ESM, but It's Not Great. For now, if you're writing CJS and you want to import an ESM script, you'll...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just had a meeting with Jed and would be grateful and willing to accept a PR that would address this.
Hello there, we need some help here! Same problem…