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

Compatibility issue: Next.js 15 and React Three Fiber - TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner') #71836

Open
kjwrld opened this issue Oct 24, 2024 · 24 comments
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Developer Experience Issues related to Next.js logs, Error overlay, etc. linear: next Confirmed issue that is tracked by the Next.js team. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Comments

@kjwrld
Copy link

kjwrld commented Oct 24, 2024

Link to the code that reproduces this issue

https://github.com/frommybrain/r3f-starter

To Reproduce

To Reproduce:

  1. Create a new Next.js 15 project using create-next-app
  2. Install React Three Fiber and its dependencies
  3. Create a simple React Three Fiber component
  4. Import and use the component in a Next.js page
  5. Run the application in development mode (next dev)
  6. Open the page in a browser
  7. Observe the error in the browser console

Current vs. Expected behavior

Current behavior: When trying to render a React Three Fiber component in a Next.js 15 application, the following error occurs:

Unhandled Runtime Error

TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')

Call Stack:
$$$reconciler
node_modules/react-reconciler/cjs/react-reconciler.development.js (498:1)
createRenderer
node_modules/@react-three/fiber/dist/index-99983b2d.esm.js (223:32)
eval
node_modules/@react-three/fiber/dist/index-99983b2d.esm.js (1728:3)
./node_modules/@react-three/fiber/dist/index-99983b2d.esm.js
file:///Users/kj/dev/experiments/r3f-starter-main/r3f-starter-app/.next/static/chunks/app/layout.js (83:1)
Next.js
eval
./node_modules/@react-three/drei/core/Environment.js
./node_modules/@react-three/drei/core/Environment.js
file:///Users/kj/dev/experiments/r3f-starter-main/r3f-starter-app/.next/static/chunks/app/layout.js (28:1)
Next.js
eval
./src/components/three/mainCanvas.jsx

Expected behavior: The React Three Fiber component should render without errors, as it does in previous versions of Next.js.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 18.19.0
  npm: 10.2.3
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 15.0.1 // Latest available version is detected (15.0.1).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

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

create-next-app, Developer Experience

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

next dev (local), next build (local), next start (local)

Additional context

This issue appears to be specific to Next.js 15 and its interaction with React Three Fiber. The error suggests a problem with React's internal workings, possibly due to changes in Next.js 15's handling of React or its bundling process. The issue occurs in the development environment and prevents the application from rendering properly.

It would be helpful to investigate any changes in Next.js 15 that might affect how it interacts with React's internals or how it bundles React-based libraries like React Three Fiber.

TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')

@kjwrld kjwrld added the bug Issue was opened via the bug report template. label Oct 24, 2024
@github-actions github-actions bot added create-next-app Related to our CLI tool for quickly starting a new Next.js application. Developer Experience Issues related to Next.js logs, Error overlay, etc. Turbopack Related to Turbopack with Next.js. labels Oct 24, 2024
@SukkaW
Copy link
Contributor

SukkaW commented Oct 25, 2024

Next.js 15 is using React 19. React 19 changes its secret internal API from SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED to __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.

React Three Fiber uses those React secret internals to access ReactCurrentOwner and thus is no longer compatible with React 19 (this should be expected since you are already using something that would result in YOU_WILL_BE_FIRED).

This is not the issue of React or Next.js, it is a bug of React Three Fiber. Please submit an issue there instead.

@AchrefHASNI
Copy link

@kjwrld better downgrade to [email protected]

@SukkaW
Copy link
Contributor

SukkaW commented Oct 26, 2024

See also: pmndrs/react-three-fiber#3222

@github-actions github-actions bot added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Oct 28, 2024
@wodka
Copy link

wodka commented Oct 28, 2024

I also having the issue using react 18 - so this seems to be not strictly related to a newer react version (I also tried 18.2, 18.3 and 19) - all with the same error happening once nextjs 15 is installed

@SukkaW
Copy link
Contributor

SukkaW commented Oct 29, 2024

I also having the issue using react 18 - so this seems to be not strictly related to a newer react version (I also tried 18.2, 18.3 and 19) - all with the same error happening once nextjs 15 is installed

Because Next.js will prefer its built-in version of React rather than your installed version.

@timneutkens timneutkens removed the Turbopack Related to Turbopack with Next.js. label Oct 29, 2024
@karlhorky
Copy link
Contributor

karlhorky commented Oct 29, 2024

@kjwrld have you tried @react-three/[email protected]?

It seems that some users are having success with that and Next.js 15:

@Your-Ehsan

This comment was marked as off-topic.

@github-actions github-actions bot added the linear: next Confirmed issue that is tracked by the Next.js team. label Nov 4, 2024
Pixelrobin added a commit to Pixelrobin/athena-crisis that referenced this issue Nov 7, 2024
Need to use the 9 beta. Potential related issue: vercel/next.js#71836
@ztanner ztanner added the Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). label Nov 7, 2024
@samcx samcx removed the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Nov 7, 2024
@KerlosSoNy
Copy link

KerlosSoNy commented Nov 23, 2024

i have solved it by downgrade my next.js to 14.2

and remove turbopack from the package.json and insure that next.config.ts to be next.config.js

@MarkoJovanovic0297

This comment was marked as off-topic.

@renoiser
Copy link

renoiser commented Nov 26, 2024

It works for me using "@react-three/fiber": "9.0.0-rc.1"

"next": "15.0.3",
"react": "19.0.0-rc-66855b96-20241106"
"react-dom": "19.0.0-rc-66855b96-20241106"

@IdrisKulubi
Copy link

Just use this npm i @react-three/fiber@alpha will solve the bug without downgrading your NextJs .

@eik-1
Copy link

eik-1 commented Dec 6, 2024

It works for me using "@react-three/fiber": "9.0.0-rc.1"

"next": "15.0.3",
"react": "19.0.0-rc-66855b96-20241106"
"react-dom": "19.0.0-rc-66855b96-20241106"

Thanks this worked for me aswell

Nanae-j added a commit to Nanae-j/fizzy-animation-site that referenced this issue Dec 21, 2024
nextのダウングレード

エラー:
TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')

参考:
vercel/next.js#71836@kjwrld better downgrade to [email protected]
@edinsoncs
Copy link

Simplemente use este npm i @react-three/fiber@alpha y resolverá el error sin degradar su NextJs.

It worked

@Ousbaiy
Copy link

Ousbaiy commented Jan 2, 2025

i got this error when building: Type error: Module '"@react-three/fiber"' has no exported member 'Object3DNode.
using this version "@react-three/fiber": "^9.0.0-alpha.8",

@ussef083
Copy link

ussef083 commented Jan 2, 2025

It works for me using "@react-three/fiber": "9.0.0-rc.1"

"next": "15.0.3",
"react": "19.0.0-rc-66855b96-20241106"
"react-dom": "19.0.0-rc-66855b96-20241106"

This version 9.0.0-rc.1 works for me , i use Nextjs 15

@jackvijayy
Copy link

@kjwrld better downgrade to [email protected]

works for me downgrade next

@jackvijayy
Copy link

[email protected]

1.npm uninstall next

2.npm install [email protected]

3.npm list next //check the version

4.update package.json:

"dependencies": {
"next": "14.2.16",
}

5.npm install

6.npm run dev

enjoy your models😁😁👋

@adityamandal-Developer
Copy link

whats the fix of this as of jan 3 2025? am getting the same error
TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')

@IdrisKulubi
Copy link

Just use this npm i @react-three/fiber@alpha will solve the bug without downgrading your NextJs .

@adityamandal-Developer
Copy link

yeah thank you it worked

@IdrisKulubi
Copy link

yeah thank you it worked

You're welcome👍

@SheIsBukki
Copy link

I had the same error today. After reading responses, I fixed it by upgrading to

@react-three/fiber@alpha and then npm install --legacy-peer-deps fixed compatibility issues

@johnidogun
Copy link

Use npm install "@react-three/fiber@alpha

as at the time I posted this message the version was "@react-three/fiber": "^9.0.0-alpha.8",

@GylanSalih
Copy link

[email protected]

1.npm uninstall next

2.npm install [email protected]

3.npm list next //check the version

4.update package.json:

"dependencies": { "next": "14.2.16", }

5.npm install

6.npm run dev

enjoy your models😁😁👋

Thank you so much! worked fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Developer Experience Issues related to Next.js logs, Error overlay, etc. linear: next Confirmed issue that is tracked by the Next.js team. Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

No branches or pull requests