Skip to content
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

Cannot import react-select/creatable #3660

Closed
brunomonteirosud opened this issue Jul 1, 2019 · 10 comments
Closed

Cannot import react-select/creatable #3660

brunomonteirosud opened this issue Jul 1, 2019 · 10 comments

Comments

@brunomonteirosud
Copy link

Hello!

I am trying to use React Select Creatable by following the last example in this page (Multi-select text input):
https://react-select.com/creatable

However, when I try to import this:

import CreatableSelect from "react-select/creatable";

I have the error:

Cannot find module react-select/creatable

I tried to create a custom.d.ts file with declare module "react-select/creatable";, and that fixed the error message but it creates other issues in the project.

I am using @types/react-select: ^2.0.19 and react-select: 2.4.3.

Here is a reproducible example, forked from the "React Select Creatable" example page mentioned above:
https://codesandbox.io/s/react-codesandboxer-example-wdrsk

Note: I am using react-select in other parts of the project and that works fine, the issue only happens when I try to specifically import react-select/creatable;

@brunomonteirosud
Copy link
Author

As an updated, I found that import CreatableSelect from "react-select"; (without specifying the creatable path) is working.

If that's how it's supposed to be now, maybe we could update the documentation in the example page. Let me know if I should open a PR for that 😄

@devilcius
Copy link

@brunomonteirosud, I think your are not importing the Creatable submodule with import CreatableSelect from "react-select", but the main ReactSelect component. I solved it with:

import { Creatable } from 'react-select';

I'm using "react-select": "^2.4.4"

@brunomonteirosud
Copy link
Author

Sorry @devilcius, I think I am little confused. Are you saying I should import like this

import { Creatable } from 'react-select';

and then use a <Creatable> component, instead of a <CreatableSelect>?

I tried that and it looks like it works, but not sure what would be the difference between those 2 components...

I am just trying to reproduce the last example (Multi-select text input) from this page:

https://react-select.com/creatable

@vferdiansyah
Copy link

@brunomonteirosud For v2 users, if you want to use Creatable, you can import it like this

import { Creatable } from 'react-select'

or like this

import Creatable from 'react-select/lib/Creatable'

and use it like <Creatable>

You can read it in the v2 to v3 upgrade guide here.

@devilcius
Copy link

@brunomonteirosud, the difference between the two compenents is that with Creatable users can create new options along with choosing existing options. When you do import CreatableSelect from "react-select"; your are actually importing the main component Select not Creatable. When you do import Something from 'package' you are actually importing the main component from that package, Something can be any name, it doesn't matter.

@brunomonteirosud
Copy link
Author

Thank you all!

@kavdev
Copy link

kavdev commented May 17, 2020

If it helps, I got this to work with v3 via:
import Creatable from "react-select/creatable/dist/react-select.esm";

@Lambdaphile
Copy link

@brunomonteirosud, I think your are not importing the Creatable submodule with import CreatableSelect from "react-select", but the main ReactSelect component. I solved it with:

import { Creatable } from 'react-select';

I'm using "react-select": "^2.4.4"

Huh... VSCode is not showing Creatable as something importable when trying to import like that but it works... Didn't know that VSCode can jebait with imports :D

@espitiachisol
Copy link

@brunomonteirosud, I think your are not importing the Creatable submodule with import CreatableSelect from "react-select", but the main ReactSelect component. I solved it with:

import { Creatable } from 'react-select';

I'm using "react-select": "^2.4.4"

thanks~~~ this works for me

@O-Q
Copy link

O-Q commented Jan 11, 2023

I solved this by changing the "moduleResolution" in tsconfig to "Node" instead of "NodeNext".

but I prefer to stick to importing from "react-select/creatable/dist/react-select-creatable.cjs" because of using "exports" field in my mono repo package which doesn't seem to work in moduleResolution "Node".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants