-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to import /async, /creatable, .etc from an ES module #4859
Comments
@srmagura would you be willing to put together a PR for this? |
Sure, I can do that this weekend. One thing to note is that this change will prevent consumers from importing from "unofficial" entry points. For example, the following hypothetical import will error: import { Blah } from 'react-select/dist/some/internal/module.ts' Only imports from the following will work: "react-select"
"react-select/base"
"react-select/animated"
"react-select/async"
"react-select/creatable"
"react-select/async-creatable" Is this okay? (I would guess you can still do type-only imports from other entry points, but I'm not sure.) |
Let me get some thoughts from Jed and some of the other collaborators in case I am missing something in this approach. I'll try to follow up by Friday. |
Just had a meeting with Jed and would be grateful and willing to accept a PR that would address this. |
Hey @ebonow, I made an attempt at this but I am unable to get even the most basic case to work... I added this to the "exports": {
".": "./dist/react-select.esm.js",
}, With this change in place, the following will fail if placed in an import Select from 'react-select' Node will resolve I think you need to publish your ES modules with the Oh, and here is the repository I created to test this out: https://github.com/srmagura/react-select-exports-test |
I don't suspect we'd want to introduce any breaking changes. I'll bring this up for further discussion and do some more investigation. |
Hello guys, Any news about this? |
Hello there, we need some help here! Same problem... |
I created the PR above to address this issue. Want to take a look @ebonow? @srmagura was on the right track, but his solution was missing the conditions to be able to support both CJS and ESM environments (as well as TS).
I tested the solution in the PR in a Webpack 5 environment and it works correctly. |
I ran into this issue on version |
I am having the same issue in version Like this - import _AsyncCreatableSelect from "react-select/async-creatable/dist/react-select-async-creatable.cjs.js";
import _AsyncSelect from "react-select/async/dist/react-select-async.cjs.js";
import _CreatableSelect from "react-select/creatable/dist/react-select-creatable.cjs.js";
const AsyncCreatableSelect = defaultImport(_AsyncCreatableSelect);
const AsyncSelect = defaultImport(_AsyncSelect);
const CreatableSelect = defaultImport(_CreatableSelect); |
Minimal repro
If placed in an
.mjs
file, the following code results in an error.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:
Suggested Solution
Utilize the
exports
field inpackage.json
as described in the Node documentation.Additional Context
The text was updated successfully, but these errors were encountered: