-
-
Notifications
You must be signed in to change notification settings - Fork 800
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
TypeError: (0 , _nanoid.nanoid) is not a function #205
Comments
Maybe CRA has some cache? Did you try to rerun it after installing new version? |
Hm.. this is unexpected |
Perhaps the problem comes from the fact that CRA does not support .cjs extension. |
CRA should use ESM or even Does CRA still use a webpack? |
Got it. It's loaded as path with file loader 🤦♂ |
Fixing
|
Perhaps specified extensions prevents browser field lookup |
@davidNHK I cloned your project, updated Nano ID by In your pull request, you didn’t replace Can you try to do it again with updating imports according to the migration guide. If you will have any problem, just give me a link to git branch to reproduce the error. |
I attempt follow the migration guide But problem still exist, PR here P.S. i also attempt change index.browser to index.web and no luck |
Same issue here |
@davidNHK everything works in the web, problem realted with Create React App test runner. |
I found the problem in the CRA jest config generator. Wait for a second, I will create pull request to CRA. |
I created pull request facebook/create-react-app#8768 Please add 👍 if you want to merge it quicker |
I also added note about CRA to docs and migration guide |
My PR was accepting. Now we need to wait a few days for the new CRA release. |
In node.js this is not working:
This works:
|
Any news on this? |
@tareqdayya Create React App maintainers accepted my PR but still do not release it. Feel free to create an issue in their repo and ask for release. I can’t help here. Ask CRA maintainers about releasing the fix, |
I face the same issue and this one work for my case. Thanks for saving 1 hour. |
I'm facing the same problem when using react testing library using nanoid version ^3.1.12 |
@antoniolobo do you use Create React App? I sent the fix to CRA, but they are still not released it. |
I updated Create React App to 4.0.0 with See more about migrating to newer CRA versions here. |
Update: solved again an entire different app by updating CRA to 4.0.0. Seems the solution for who is using:
|
I'm having the same issue when running on Code Sandbox. It seems to work fine below version 3.1.17 of nanoid. Is this related, or could it be an issue with Code Sandbox? |
Just had the same issue on code sandbox too. I am not sure where to look at. The demo from @tsAppDevelopment works ok with |
For anyone that is still facing the issue. ESM can’t import named CJS exports unless CJS scripts execute out of order So you can do this:
but you can't do this:
That’s because CJS scripts compute their named exports as they execute, whereas ESM’s named exports must be computed during the parsing phase. A workaround is
|
I trying upgrade nanoid from 2.x to 3.x in CRA environment
The export value from
nanoid
is always undefinedAnd i got error when running below jest test
Console message
Also i try below test
Console message
The text was updated successfully, but these errors were encountered: