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

Warn in @babel/plugin-proposal-private-property-in-object fallback #15687

Merged
merged 8 commits into from Jun 8, 2023

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jun 6, 2023

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This is a better workaround for the create-react-app that replaces #15658. It warns when the fallback is triggered, explaining users how to fix the problem.

This is the code of the fallback package:

maybeWarn: try {
  var stackTraceLimit = Error.stackTraceLimit;
  Error.stackTraceLimit = Infinity;
  var stack = new Error().stack;
  Error.stackTraceLimit = stackTraceLimit;
  if (!stack.includes("babel-preset-react-app")) break maybeWarn;

  // Try this as a fallback, in case it's available in node_modules
  module.exports = require("@babel/plugin-transform-private-property-in-object");

  setTimeout(console.warn, 2500, `\
\x1B[0;33mOne of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it \x1B[1mmay break at any time\x1B[0;33m.

babel-preset-react-app is part of the create-react-app project, \x1B[1mwhich
is not maintianed anymore\x1B[0;33m. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.\x1B[0m
  `);

  return;
} catch (e) {}

throw new Error(`\
--- PLACEHOLDER PACKAGE ---
This @babel/plugi-proposal-private-property-in-object version is not meant to
be imported. Something is importing
@babel/plugi-proposal-private-property-in-object without declaring it in its
dependencies (or devDependencies) in the package.json file.
Add "@babel/plugin-proposal-private-property-in-object" to your devDependencies
to work around this error. This will make this message go away.
`);

@babel-bot
Copy link
Collaborator

babel-bot commented Jun 6, 2023

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/54631/

@ehoogeveen-medweb
Copy link
Contributor

Not part of the changes in this pull request, but s/plugi-proposal-private-property-in-object/plugin-proposal-private-property-in-object/ in the plugin here and here.

@nicolo-ribaudo
Copy link
Member Author

Oh thank you

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Jun 8, 2023

The reason I considered adding the explicit workaround/fallback for create-react-app, instead of just erroring like for everyone else, is that I thought that create-react-app is very popular with 4 millions downloads per month. It turns out it has just ~100k downloads/week, and there has been some anomality in April that gave averaged to 4M/month.

Maybe it's ok to error as or everyone else, and users can still work around the error by explicitly adding the package to their config.

@ehoogeveen-medweb
Copy link
Contributor

Those are some weird spikes! Daily downloads between 2022-04-01 and 2022-05-01:
image
The last maintenance release was on 2022-04-12 but that didn't produce much of a bump compared to the period between 2023-04-02 and 2023-04-22.

@nicolo-ribaudo
Copy link
Member Author

CI failures are unrelated, they are just because we enabled the import assertions syntax in test262.

@nicolo-ribaudo nicolo-ribaudo merged commit 69e83d5 into babel:main Jun 8, 2023
53 of 54 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the preset-env-dep-fallback branch June 8, 2023 16:06
@Jesse1989pp
Copy link

Trying to pinpoint an issue Not sure where to address the issue, as the proposal plugin is stating this version should not be used. @nicolo-ribaudo You maybe understand what is happening here?

@nicolo-ribaudo
Copy link
Member Author

This version of the package should indeed not be used. We had to add it back as a dependency due to a bug with create-react-app, but nothing should be require()ing it. Do you have a stack trace that points out why this dependency is being loaded?

@@ -22,7 +22,7 @@
"@babel/helper-validator-option": "workspace:^",
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "workspace:^",
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "workspace:^",
"@babel/plugin-proposal-private-property-in-object": "^7.21.0",
"@babel/plugin-proposal-private-property-in-object": "condition:BABEL_8_BREAKING ? : 7.21.0-placeholder-for-preset-env.2",

Choose a reason for hiding this comment

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

Could this ternary require two values?

Copy link
Member Author

Choose a reason for hiding this comment

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

This ternary is just to make sure that the dependency will be automatically removed in Babel 8, in the published package it's being resolved to 7.21.0-placeholder-for-preset-env.2

@Jesse1989pp
Copy link

Jesse1989pp commented Jun 9, 2023

This version of the package should indeed not be used. We had to add it back as a dependency due to a bug with create-react-app, but nothing should be require()ing it. Do you have a stack trace that points out why this dependency is being loaded?

@nicolo-ribaudo I've seen two share already:

For me it's also just referring to my babel loader

@nicolo-ribaudo
Copy link
Member Author

Those two screenshots are bugs with Nuxt's Babel preset and create-react-app. Nuxt is releasing a fix soon (nuxt/nuxt#21488), while the dependency 7.21.0-placeholder-for-preset-env.2 is explicitly for the CRA bug because CRA is not maintained anymore, so we can't expect them to fix it.

For me it's also just referring to my babel loader

Could you share your package.json and your Babel configuration? Our error messages are not great sometimes 😅

@Jesse1989pp
Copy link

Sorry @nicolo-ribaudo! Thanks for the quick action. For me personally it's coming from nuxt as-well.

@nicolo-ribaudo
Copy link
Member Author

Oh good, hopefully the fix will be released soon :)

Unfortunately due to how node_modules hoisting works in npm it sometimes happens that packages forget to define a dependencies (because it's already in their node_modules for unrelated reasons), and when the node_modules layout changes this may break.

@XiaoWinter
Copy link

XiaoWinter commented Jun 12, 2023

what reason I found the issuse is my project report a error when it install,

This @babel/plugin-proposal-private-property-in-object version is not meant to
be imported

I don't know what cause it, but the ci build must be run at that time, so I had to fix the version of this babel plugin to "^7.21.0",Even though it seems unrelated now,when I read something about "semver" today. luckly the 7.21.11 be installed that time. ^_^.maybe Babel just happened to publish it.

I'm not familiar with Open source project version management .I found the version logfile just now,but I still have some doubts after reading it . why did the version be called "7.21.0-placeholder-for-preset-env.2", what does the "placeholder-for-preset-env.2" represet .

@nicolo-ribaudo
Copy link
Member Author

placeholder-for-preset-env.2 is a temporary version that we had to add as a dependency of preset-env to avoid breaking compatibility with a popular unmaintained package. It should never be loaded.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 13, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants