babel: Odd 'loose' mode configuration must be the same...
'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties and @babel/plugin-proposal-private-methods
I’m getting this error even though I don’t use either of the proposals explicitly.
Thus, it’s kinda hard for me to configure their loose modes 😆
I think they are brought in through a preset.
My config is:
"babel": {
"plugins": [
"babel-plugin-macros"
],
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": false,
"shippedProposals": true,
"debug": false
}
]
]
},
"babelMacros": {
"styledComponents": {
"pure": true
}
},
I’ve recently done yarn upgrade and this error showed up.
Summary of babel versions that got upgraded in yarn.lock:
- 7.9.6 → 7.10.0: core, runtime, compat-data, generator, helpers, parser, traverse, types, helper-compilation-targets, helper-create-class-features-plugin, helper-replace-supers, …
- 7.8.6 → 7.10.0: template
- 7.8.3 → 7.10.0: helper-member-expressions-to-function, plugin-transform-spread
- 7.9.0 → 7.10.0: plugin-transform-for-of
- …
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 21 (9 by maintainers)
I have the same problem with Storybook (
v6.0.0-beta.15).After a lot of debugging, we found that simply adding the plugins (without options) seems to work.
We don’t use the plugins directly in our app but it seems they’re included in
env. Without them listed inpluginsit fails, listing them withloose: truealso fails so I can only assume that the ‘default’ doesn’t trigger the warningI’ll try and upload the lockfile with the business-sensitive bits removed later today
In my case the problem was in mismatch between private fields and private methods
looseproperty value.we found that you need to manually add plugin and specify
loosevalue for that plugin because loose property defined on the top configuration of preset-env can be ignoredMore details on this PR https://github.com/babel/babel/pull/11634/files#diff-b307be8976e67ba330a71917a3322a94R1-R4
So config will look like the next one
or for storybook main.js in my case
We’re experiencing this failure on our Storybook build, but not our main Webpack build (and they use the same babel.config.js file). Ultimately the “fix” was deleting and recreating the yarn.lock.
TL;DR
concise work-around:
I’m looking for a wait to have my project set with
"loose": falsebut while still allowing storybook to work.Just leaving my insight here too. Working off of @JoshRobertson’s suggestion, i found all the packages that inadvertently depended on babel using
yarn why(I had both direct dependencies and some larger packages like storybook and jest). I removed them then fresh installed them recreating the dependency graph only on these parts of the yarn.lock, rather than the whole thing.In summary:
yarn why @babel/coreyarn remove @bable/core jest @storybook/react… etcyarn add @bable/core jest @storybook/react… etc@morinted
"loose": falseis the default and it should work if you upgrade all@babel/depsto latest versions. Please share a reproduction repo.Ok, I think that the problem is that Parcel is bringing in
@babel/preset-env, which is bringing in theprivate-methodsplugin causing the bug tracked in this issue. You can’t reproduce it locally because your lockfile containspreset-env@7.9.0, but for some reasons Gitlab CI is ignoring the lockfile and downloading version 7.10.0.You can workaround this Babel bug (until it’s fixed) by using
npm ciinstead ofnpm installon CI, so that it respects your lockfile.https://github.com/nano-react-app/babel-preset-nano-react-app/blob/master/index.js
This code works with 7.9 but not with 7.10:
CRA sets class properties to loose 😃
https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/create.js#L151