fix(gatsby-plugin-netlify-cms): react18-compatible require resolve #35365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Hello,
Currently with both
latest
andnext
versions ofgatsby-plugin-netlify-cms
are not fully compatible withreact@18
, and throw an error. Also reproducible withgatsby-starter-netlify-cms
if upgraded toreact@18
:The issue seems to be related to how the plugin is utilizing the
WebpackCopyPlugin
to copy theumd
distribution ofreact
andreact-dom
:gatsby/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js
Lines 210 to 222 in 0809c20
With version 18 of
react
andreact-dom
theexports
field has been added, which unfortunately does not include any of theumd
distributions:https://github.com/facebook/react/blob/e8f4a6653dc3f5d9702236a3abed887ca44dcfbb/packages/react/package.json#L22
Reading between the lines of the NodeJS Resolution Algorithm it seems only the defined subpath in
"exports"
can be imported by a consumer - thus the error.Proposal
For this, I can propose always
require.resolve
-ing thepackage.json
and navigate to theumd
scripts from there. This seems somewhat future-proof due to the following discussion, where from my understanding, the overall desire is to always allowrequire.resolve
of thepackage.json
file, regardless of its entry in the"exports"
field:nodejs/node#33460
Related Issues
Fixes: #35364