Skip to content

Next.js v10.0.0 forces React v17 to be installed #18518

@jaydenseric

Description

@jaydenseric

Bug report

Describe the bug

next v10.0.0 forces react v17 to be installed, even if the project has react v16 in dependencies.

This is because next v10.0.0 has a use-subscription v1.5.0 dependency pinned:

"use-subscription": "1.5.0",

use-subscription v1.5.0 has a react peer dependency of ^17.0.0 (v16 not supported):

https://unpkg.com/[email protected]/package.json

With a project that has a react v16 dependency, npm v6 at install time would emit a warning that the use-subscription peer dependency on react is not satisfied, but it would not install react v17. While this may seem ok, it probably is not because use-subscription declared react v16 is not supported, so who knows if it will have problems in it's function.

With npm v7, which automatically installs peer dependencies as needed, this results in react v16 being installed to fulfill the project dependency, and react v17 to fulfill the use-subscription peer dependency. The result is that multiple versions of react get installed, and this can cause a React render error that multiple instances of React are being used with hooks.

To Reproduce

  1. In a hello-world Next.js project, ensure React v16 is specified in the package dependencies.
  2. Use npm v7 to install the project.
  3. Run npm ls react to see the multiple versions installed. This in itself is bad.
  4. At this point, you could try to run npm run dev to see if you get the same React render error I do in my project about hooks and multiple React instances, but I'm not 100% sure if it will happen out of the box or if you need to use some particular hooks to see the issue.

Expected behavior

When used with npm v6 or v7, next should respect the version of react installed in the user's project, and not cause multiple versions of react to be installed.

Screenshots

Screen Shot 2020-10-30 at 2 36 21 pm

System information

  • OS: macOS 10.15.7
  • Version of Next.js: 10.0.0
  • Version of Node.js: Any compatible with npm v6, v7
  • Version of npm: v7 especially

Metadata

Metadata

Assignees

Labels

UpstreamRelated to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions