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

^13.0.0 uses a compiled React version which is incompatible with React 18.2.0 #42745

Closed
1 task done
eddeee888 opened this issue Nov 10, 2022 · 3 comments
Closed
1 task done
Labels
area: app App directory (appDir: true) kind: bug Confirmed bug that is on the backlog

Comments

@eddeee888
Copy link

eddeee888 commented Nov 10, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
    Binaries:
      Node: 16.15.0
      npm: 8.5.5
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.0.3-canary.3
      eslint-config-next: 13.0.2
      react: 18.2.0
      react-dom: 18.2.0

Which example does this report relate to?

None

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

The normal React version in create-next-app is 18.2.0
nextConfig.experimental.appDir=true uses compiled react version which is 18.3.0-next-28a574ea8-20221027.
This causes types errors when using libraries like react-hook-form because of version mismatch:

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
error - TypeError: Cannot read properties of null (reading 'useRef')
    at Object.useRef (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/react/cjs/react.development.js:1630:21)
    at useForm (file:///Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/react-hook-form/dist/index.esm.mjs:2267:32)
    at Home (webpack-internal:///./pages/index.tsx:23:83)
    at renderWithHooks (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7629:16)
    at renderIndeterminateComponent (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7702:15)
    at renderElement (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7927:7)
    at renderNodeDestructiveImpl (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8094:11)
    at renderNodeDestructive (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8066:14)
    at renderIndeterminateComponent (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7756:7)
    at renderElement (/Users/eddeee888/Projects/eddeee888/next-compiled-react/next-compiled-react/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7927:7) {
  page: '/'

Expected Behavior

There is no React version clashes when using appDir config

To Reproduce

From scratch

  1. Run yarn create-next-app and go through the prompts
  2. Run yarn add react-hook-form
  3. Set (next.config.js).nextConfig.experimental.appDir=true
  4. Import and call useForm in pages/index.ts
  5. Run yarn dev
  6. Error shows up in terminal

Or using what's in this repo

https://github.com/eddeee888/next-13-0-2-compiled-react

  1. Run yarn install to install packages
  2. Run yarn dev
  3. Error shows up in the terminal
@eddeee888 eddeee888 added the examples Issue/PR related to examples label Nov 10, 2022
@eddeee888
Copy link
Author

Sorry, I thought area: examples is meant to be used for issues with reproducible repos.
Please remove the area: examples tag 🙏

@balazsorban44 balazsorban44 added kind: bug Confirmed bug that is on the backlog area: app App directory (appDir: true) and removed examples Issue/PR related to examples labels Nov 10, 2022
@huozhi
Copy link
Member

huozhi commented Nov 11, 2022

This is resolved by #42741, verified with next 13.0.3 it works with the reproduction

@huozhi huozhi closed this as completed Nov 11, 2022
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. 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 Dec 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) kind: bug Confirmed bug that is on the backlog
Projects
None yet
Development

No branches or pull requests

3 participants