-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Attempted import error: 'useRef' is not exported from 'react' (imported as 'React') #60890
Comments
Same issue here with In addition I am getting this error, which is maybe related:
Interestingly, the problems are gone when I use |
That is interesting, it's working for me when I do that as well, just wish the build would work so I could deploy it 😢 |
Happening to me as well with several imports, all from React ( |
workaround to issue introduced in next.js 14.1.0 (vercel/next.js#60890) that only seems to affect dev builds for me
I'm having the same issue. The error occurs for the first time in 14.0.5-canary.20 |
Same here, as soon as I upgraded it's refused to work, lists several different react imports in the error logs like what you said. |
Solved this problem in next js 14.1.0, solution: |
I don't have a browserslist config in my package.json :/ |
It helped, thanks! |
Thanks! It worked, but only after I also deleted the .next folder. |
I thought the issue for me was that I was accidentally importing something into middleware that wasn't being tree shaken properly, but I guess it's not based on other comments? Don't have browserlists in package.json so I cannot delete that. For me it doesn't crash the build process, but just pollutes my terminal during development or build and I'm also not sure if something might break during runtime later when app is running. It also doesn't list React imports as problematic, but rather a react-hook-form export. I get this message multiple times:
|
It's very random, I originally had an issue with an import from the |
Likewise, one of the discoveries I also came across while I was trying to figure it out. |
Solved to me, thanks! |
Going off #60909, we've worked around this by adding
|
+1 . Build is breaking showing the following error "Attempted import error: 'useRef' is not exported from 'react' (imported as 'e')." after upgrading from 14.0.4. I've tried removing |
Worked for me thanks, delete |
This did not work for me |
Make sure you delete your .next folder before running "run dev" again |
The app is running inside a docker container so there was no next folder to begin with |
Works for me when I do that, after clearing out the .next folder between runs. For example Old browserslist && no .next directory --- delete .next directory Although I don't know how this bug was introduced, and if browserslistrc is even the cause, or just working because it doesn't break in some way; I just have a black box understanding of what next dev does behind the scenes. I'm unsure if this is necessarily a fix for this bug, because there are others with no .browserslistrc or no .next folder (example above) that are still running into the issue. I do appreciate the temporary solution, at least for me, for the time-being, thank you. I tried the latest canary with it last night, with the original browserslist, and ran into the same error, so I'm going to still count it as broken. |
@cthacker-udel I'm not sure what's going on with next dev behind the scenes either, but I'm glad this temporary solution worked for you. @alessandrojcm Another temporary solution that might work for you is changing your package.json, such that it runs "next dev" with the experimental/beta turbo flag:
This works for me, even without the browserlist tweak. However, I need to run without the turbo flag because it's still in beta, and it breaks the functionality of some of my pages. It might help you though |
@NanningR last time I tried turbo it wasn't quite working for me, I'll try again thanks. @mikesprague fwiw this does affect production for me as well, the build step fails with the same error. |
I have this issue in all my routes, once in Swiper and once in a OIDC client component. This happened since upgrading to 14.1 and all attempts to workaround it failed (browserlist, deleting .next folder, modifying the code). Not using turbo. With a browserlist config file Webpack fails right away:
|
Adding this to package.json finally solved this issue. Deleted node_modules/.cache and .next folders. During the first run there where many errors but after that the app runs again.
Hope the root cause will be fixed soon to remove this workaround again. |
I just found the fix, In my case I was using one Rule is if you're using any client side library then make sure that you're not using its client apis/functions directly or indirectly on server routes or server actions. |
I had this too - I didn't have browserslist but it popped up when I used the shad-cn dropdown-ui component. I had to add |
Thank you, worked for me after removing |
### What Exclude precompiled react packages from browser layer loaders coverage. ### Why Since we're transpiling all the browser layer code now after #59569, then SWC will also compile react. But when it compiles `react.production.min.js` it gives me with the code and ESM helper inserted ```js import { _ as _type_of } from "@swc/helpers/_/_type_of"; // This is not correct var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Sym bol.for("react.strict_mode"), r = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.f ``` This makes bundler think it's a ESM package but actually it's CJS, which converts the module into `{ default: .., __esModule }` instead of the original react module. When you're using `React.useEffect` or other API through namespace import (`import * as React from 'react'`), this will break the module exports check in bundling as the property doesn't directly attached to the module now. This PR disabled the transform for precompiled react packages now and will see the deeper issue in next-swc side later. Fixes #60890 Fixes #61185 Closes NEXT-2362
I am getting a similar error upgrading to 14.1, the error comes from chakra. I have tried everything except upgrading to turbo. Any ideas?
|
We had a fix in #61791 and released in v14.1.1-canary.44 for this issue 🙏 |
- Convert function declarations to fat arrows. - Use experimental Turbo builder in development.
* chore: update ts-morph to v21.0.1 to match TS 5.3 https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/CHANGELOG.md#2100-2023-12-02 * fix: random next error on playground vercel/next.js#60890
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
### What Exclude precompiled react packages from browser layer loaders coverage. ### Why Since we're transpiling all the browser layer code now after #59569, then SWC will also compile react. But when it compiles `react.production.min.js` it gives me with the code and ESM helper inserted ```js import { _ as _type_of } from "@swc/helpers/_/_type_of"; // This is not correct var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Sym bol.for("react.strict_mode"), r = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.f ``` This makes bundler think it's a ESM package but actually it's CJS, which converts the module into `{ default: .., __esModule }` instead of the original react module. When you're using `React.useEffect` or other API through namespace import (`import * as React from 'react'`), this will break the module exports check in bundling as the property doesn't directly attached to the module now. This PR disabled the transform for precompiled react packages now and will see the deeper issue in next-swc side later. Fixes #60890 Fixes #61185 Closes NEXT-2362
Link to the code that reproduces this issue
https://github.com/cthacker-udel/BugRepros
To Reproduce
My layout.tsx:
Result:
Current vs. Expected behavior
Current: Crashing using
next dev
, and crashing duringnext build
, completely blocking development.Expected: Working as it was before updating next to latest
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Module resolution (CJS / ESM, module resolving)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), Vercel (Deployed)
Additional context
The bug is in the
tanstackbug
folder of the repoNEXT-2362
The text was updated successfully, but these errors were encountered: