Yarn berry error: react not in dependencies
kryp71c opened this issue · comments
Version affected: v0.15.2 and below
In my case using yarn@3.2.0 with workspaces, PnP, and zero installs
When using yarn berry, starting a dev server or build fails with the following error:
Error: next-image-export-optimizer tried to access react, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
Workaround is to explicitly add the dependency to .yarnrc.yml
followed by a new yarn install
:
packageExtensions:
"next-image-export-optimizer@*":
dependencies:
"react": "*"
Hi @kryp71c,
I am not familiar with yarn. Would adding react to the peerDependencies in the package.json be sufficient?
Currently, it only specifies next:
"peerDependencies": {
"next": "12.x"
},
Yes, React needs to be added as a peer dep. The only question is, what should the semver range be? ^18.0.0
?
So next.js itself specifies the following peer dependencies:
"peerDependencies": {
"fibers": ">= 3.1.0",
"node-sass": "^6.0.0 || ^7.0.0",
"react": "^17.0.2 || ^18.0.0-0",
"react-dom": "^17.0.2 || ^18.0.0-0",
"sass": "^1.3.0"
},
I think we can do the same with regards to the react version.