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

fix(gatsby-plugin-netlify-cms): react18-compatible require resolve #35365

Conversation

kspeyanski
Copy link
Contributor

Description

Hello,

Currently with both latest and next versions of gatsby-plugin-netlify-cms are not fully compatible with react@18, and throw an error. Also reproducible with gatsby-starter-netlify-cms if upgraded to react@18:

Package subpath './umd/react.production.min.js' is not defined

The issue seems to be related to how the plugin is utilizing the WebpackCopyPlugin to copy the umd distribution of react and react-dom:

new CopyPlugin({
patterns: externals.flatMap(
({ name, assetName, sourceMap, assetDir }) =>
[
{
from: require.resolve(path.join(name, assetDir, assetName)),
to: assetName,
},
sourceMap && {
from: require.resolve(path.join(name, assetDir, sourceMap)),
to: sourceMap,
},
].filter(Boolean)

With version 18 of react and react-dom the exports field has been added, which unfortunately does not include any of the umd 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 the package.json and navigate to the umd scripts from there. This seems somewhat future-proof due to the following discussion, where from my understanding, the overall desire is to always allow require.resolve of the package.json file, regardless of its entry in the "exports" field:
nodejs/node#33460

Related Issues

Fixes: #35364

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 7, 2022
@kspeyanski kspeyanski force-pushed the fix/gatsby-plugin-netlify-cms/require-resolve branch 2 times, most recently from 6c6b5a1 to 1cef47b Compare April 10, 2022 07:06
@marvinjude marvinjude added topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Apr 10, 2022
@kspeyanski kspeyanski force-pushed the fix/gatsby-plugin-netlify-cms/require-resolve branch from 1cef47b to 123bfd4 Compare April 11, 2022 09:24
@kspeyanski kspeyanski force-pushed the fix/gatsby-plugin-netlify-cms/require-resolve branch from 123bfd4 to 79c4954 Compare April 14, 2022 05:23
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Change makes total sense

@pieh pieh added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Apr 14, 2022
@gatsbybot gatsbybot merged commit 5698ada into gatsbyjs:master Apr 14, 2022
@kspeyanski kspeyanski deleted the fix/gatsby-plugin-netlify-cms/require-resolve branch April 14, 2022 12:21
@i-am-the-slime
Copy link

Is this released in any way? Can I use it? I have this error

@chocobuckle
Copy link

This fix included in the latest release? I tried installing v6.12.1 but still getting the same error.

@LekoArts
Copy link
Contributor

LekoArts commented Apr 26, 2022

It'll be released today, new minor releases are happening every two weeks. If it is published in a patch version, the PR will receive a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gatsby-plugin-netlify-cms react-18 require.resolve
7 participants