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

[v12.1.0] Using React 18 prevents starting without experimental in config (TypeError: Cannot set properties of undefined (setting 'reactRoot')) #34499

Closed
1 task done
bennettdams opened this issue Feb 17, 2022 · 3 comments · Fixed by #34500
Labels
bug Issue was opened via the bug report template.

Comments

@bennettdams
Copy link
Contributor

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 16.13.0
  npm: 8.1.0
  Yarn: 1.22.5
  pnpm: N/A
Relevant packages:
  next: 12.1.0
  react: 18.0.0-rc.0
  react-dom: 18.0.0-rc.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Starting with v12.1.0, you can't use React 18 when you don't use the experimental field in the next.config.js

image

That's because this recent change sets reactRoot on the user's config without checking if the key already exists:

const hasReactRoot = shouldUseReactRoot()
if (hasReactRoot) {
userConfig.experimental.reactRoot = true
}

Expected Behavior

  • React 18 should be usable without using the experimental field in the next.config.js
    or
  • the docs for React 18 should mention that it is mandatory to set the field

To Reproduce

  1. Install via Create Next App
    npx create-next-app@latest --ts --use-npm .
  2. Install React 18
    npm install next@latest react@rc react-dom@rc
  3. Start the app
    npm run dev
@bennettdams bennettdams added the bug Issue was opened via the bug report template. label Feb 17, 2022
@kodiakhq kodiakhq bot closed this as completed in #34500 Feb 17, 2022
kodiakhq bot pushed a commit that referenced this issue Feb 17, 2022
Fixes #34499 

Starting with `v12.1.0`, you can't use React 18 when you don't use the `experimental` field in the `next.config.js`

![image](https://user-images.githubusercontent.com/29319414/154569017-38f72690-6879-47d1-a0cd-09072af2967c.png)

That's because [this recent change](1aee935) sets `reactRoot` on the user's config without checking if the key already exists:

https://github.com/vercel/next.js/blob/787186a85a054ea870fc964583fe65e9f2286354/packages/next/server/config.ts#L679-L682


This change initializes `experimental` on the `userConfig` if necessary.



## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
@clianor
Copy link

clianor commented Feb 18, 2022

I fixed this by modifying next.config.js as follows:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  experimental: {
    reactRoot: true
  }
}

module.exports = nextConfig

@bennettdams
Copy link
Contributor Author

@clianor Yep, that works. I created a PR that fixes this, which already got merged, so in the next release that shouldn't be needed anymore.

@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 Mar 21, 2022
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants