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

[Block] 14.1.0 next dev throw error Attempted import error: 'useLayoutEffect' is not exported from 'react' (imported as 'useLayoutEffect'). #61185

Closed
tianyingchun opened this issue Jan 26, 2024 · 10 comments · Fixed by #61791
Labels
bug Issue was opened via the bug report template. locked

Comments

@tianyingchun
Copy link

Link to the code that reproduces this issue

https://github.com/tianyingchun/next-issue

To Reproduce

  1. yarn install
  2. yarn dev

Current vs. Expected behavior

throw error in next dev mode

- info Server env(s) validation successful:
- info Server env(s) validation successful:
   ▲ Next.js 14.1.0
   - Local:        http://localhost:3000
   - Environments: .env

 ✓ Ready in 4s
 ✓ Compiled /src/middleware in 91ms
 ✓ Compiled (148 modules)
 ○ Compiling /[locale]/[...rest] ...
 ⨯ ./node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.mjs
Attempted import error: 'useLayoutEffect' is not exported from 'react' (imported as 'useLayoutEffect').

Import trace for requested module:
./node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.mjs
./node_modules/@mui/base/Unstable_Popup/Popup.js
./node_modules/@mui/base/Unstable_Popup/index.js
./node_modules/@mui/base/index.js
./node_modules/@mui/material/Popover/Popover.js
./node_modules/@mui/material/Popover/index.js
__barrel_optimize__?names=Popover!=!./node_modules/@mui/material/index.js
./node_modules/material-ui-popup-state/es/HoverPopover.mjs
./src/components/LocaleSwitcher/LocaleSwitcher.tsx
 ⨯ ./node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.mjs
Attempted import error: 'useLayoutEffect' is not exported from 'react' (imported as 'useLayoutEffect').

Import trace for requested module:
./node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.mjs
./node_modules/@mui/base/Unstable_Popup/Popup.js
./node_modules/@mui/base/Unstable_Popup/index.js
./node_modules/@mui/base/index.js
./node_modules/@mui/material/Popover/Popover.js
./node_modules/@mui/material/Popover/index.js
__barrel_optimize__?names=Popover!=!./node_modules/@mui/material/index.js
./node_modules/material-ui-popup-state/es/HoverPopover.mjs
./src/components/LocaleSwitcher/LocaleSwitcher.tsx
 ⚠ Fast Refresh had to perform a full reload due to a runtime error.

yarn build works fine.

Provide environment information

- info Server env(s) validation successful:

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 4.0.2
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

  1. next dev can works correct on "next": "14.0.4",
  2. next dev can not works correct on "next": "14.1.0",
  3. next build can works correct both on 14.0.4 and 14.1.0****
@tianyingchun tianyingchun added the bug Issue was opened via the bug report template. label Jan 26, 2024
@cthacker-udel
Copy link

Very similar bug: #60890

@zamarawka
Copy link

zamarawka commented Jan 27, 2024

I encountered exactly the same error after update on 14.1.0.
Every import from react with error.

Don't understand how, but

rm -rf .next

with remove browserList from package.json helps to run app..

@limpep
Copy link

limpep commented Jan 28, 2024

Getting the same error

@NewEditOfficial
Copy link

NewEditOfficial commented Feb 4, 2024

I encountered exactly the same error after update on 14.1.0. Every import from react with error.

Don't understand how, but

rm -rf .next

with remove browserList from package.json helps to run app..

I was getting same error this tip resolved it temporarily until its fixed.👍

  • next dev --turbo (i was required to changed package.json scripts >> dev to make it work)

@gaojude
Copy link
Contributor

gaojude commented Feb 6, 2024

I encountered exactly the same error after update on 14.1.0. Every import from react with error.

Don't understand how, but

rm -rf .next

with remove browserList from package.json helps to run app..

what if i do need this field for other purposes? is there a way for next.js build to not look at the browserList field even when its there?

@mrksph
Copy link

mrksph commented Feb 8, 2024

This is a joke, how do you suggest to upgrade to the latest version with stupid errors like this? Thank god all I have to do is delete a .next folder and a property from package.json.... When will this fix be released? @huozhi ?

Btw, thanks for the work around @zamarawka

@huozhi
Copy link
Member

huozhi commented Feb 8, 2024

We had a fix in #61791 and released in v14.1.1-canary.44 for this issue, please upgrade to any canary versions above that one

@Eunkyung-Son
Copy link
Contributor

Eunkyung-Son commented Feb 21, 2024

This error occurs during build time on pages using the edge runtime.
Removing the edge runtime and using the node runtime resolves this error.

Do you have any solution for this issue?

image
image

huozhi added a commit that referenced this issue Feb 28, 2024
### 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
@rakibatomnixima
Copy link

still having this error on latest canary build on edge runtime

Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants