babel: [Bug]: Cannot read properties of undefined (reading 'addHelper')
đź’»
- Would you like to work on a fix?
How are you using Babel?
babel-loader (webpack)
Input code
part of package.json
"@babel/polyfill": "7.12.1",
"@babel/cli": "7.17.6",
"@babel/core": "7.17.9",
"@babel/eslint-parser": "7.17.0",
"@babel/eslint-plugin": "7.17.7",
"@babel/plugin-proposal-export-default-from": "7.16.7",
"@babel/preset-env": "7.16.11",
"@babel/preset-react": "7.16.7",
"@commitlint/cli": "^17.3.0",
"@jcroall/detect-gitlab-report": "1.0.2",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
"@svgr/webpack": "6.2.1",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "12.1.5",
"autoprefixer": "9.8.8",
"babel-jest": "27.5.1",
"babel-loader": "8.2.5",
"babel-plugin-transform-imports": "1.5.1",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
Configuration file name
No response
Configuration
babel.config.json
{
presets: [['@babel/preset-env', { modules: false }], '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-export-default-from'],
}
Current and expected behavior
I think it’s a bug of latest published version, project is built on remote CI server,
about an hour ago, we got an error on npm install
npm ERR! notarget No matching version found for @babel/plugin-transform-async-generator-functions@^7.22.7.
because internal npm mirror server did not sync the latest version
but after the server synced, we got another error on npm build
via webpack
TypeError: /builds/project/file-in-project-thunk.js: Cannot read properties of undefined (reading 'addHelper')
at Scope.toArray (/builds/project/node_modules/@babel/traverse/lib/scope/index.js:464:36)
at DestructuringTransformer.toArray (/builds/project/node_modules/@babel/plugin-transform-destructuring/lib/index.js:108:25)
at DestructuringTransformer.pushArrayPattern (/builds/project/node_modules/@babel/plugin-transform-destructuring/lib/index.js:242:26)
at DestructuringTransformer.push (/builds/project/node_modules/@babel/plugin-transform-destructuring/lib/index.js:97:12)
at DestructuringTransformer.init (/builds/project/node_modules/@babel/plugin-transform-destructuring/lib/index.js:272:10)
at convertVariableDeclaration (/builds/project/node_modules/@babel/plugin-transform-destructuring/lib/index.js:341:21)
at PluginPass.VariableDeclaration (/builds/project/node_modules/@babel/plugin-transform-destructuring/lib/index.js:536:9)
at newFn (/builds/project/node_modules/@babel/traverse/lib/visitors.js:159:14)
at NodePath._call (/builds/project/node_modules/@babel/traverse/lib/path/context.js:46:20)
at NodePath.call (/builds/project/node_modules/@babel/traverse/lib/path/context.js:36:17)
Environment
cannot reproduce on local machine, the error is on CI server.
Possible solution
No response
Additional context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 23
- Comments: 38 (10 by maintainers)
Commits related to this issue
- pinning babel to avoid upstream bug https://github.com/babel/babel/issues/15752 — committed to embroider-build/embroider by ef4 a year ago
- Update babel dependencies to avoid addHelper issue in FabricExample See https://github.com/babel/babel/issues/15752 — committed to zatteo/react-native-cameraroll by zatteo 7 months ago
I’m releasing version 7.22.8 of
@babel/core
and@babel/traverse
, you can follow the progress at https://github.com/babel/babel/actions/runs/5475383648.Overriding @babel/traverser to last version worked for us Add this to package.json “overrides”: { “@babel/traverse”: “7.22.6” },
As a workaround, try using
resolutions
to pin to an older@babel/traverse
version.I can back up what @mendrixsebas is saying – I had to do the following because I use yarn though
I tracked down the cause of the bug to using
@babel/traverse@7.22.6
with@babel/core@7.22.5
or older.Use a
package-lock.json
/yarn.lock
file, and usenpm ci
/yarn --frozen-lockfile
instead ofnpm install
/yarn
to download deps.“resolutions”: { “@babel/traverse”: “7.23.2”, “@babel/core”: “7.23.2” }
this not work for me
I had to install to version 0.72.5 to resolve this issue.
"overrides": { "@babel/traverse": "7.22.8" }
works, but when using 7.22.10 or 7.22.11 the error has returned@nicolo-ribaudo Yes I am still facing issue with react project
Build fail
For the source of the issue it’s indeed to have 2
@babel/core
packagesIn my case though it's a problem with yarn and renovate creating a split deps when it's not needed resulting in the following yarn.lock
This is really a messy yarn.lock,
so I forced a rebuild using `yarn upgrade` which now merged the deps
Which fixed the issue
I can confirm that the issue on angular has been fix with the update đź‘Ť
Thank you @nicolo-ribaudo for the swift fix !
Beat me to it, it’s good practice to do that in every project so that you only upgrade deps on production once they have been tested and released, this will prevent you supply chain attacks and headaches with broken deps
I have not found the cause of the bug yet, but https://github.com/babel/babel/pull/15754 should probably make it away until when I figure out how to properly fix it.
With the recent release we also received similar reports in Angular CLI for
path.hub.file
. See: https://github.com/angular/angular-cli/issues/25496The issue appears to happen when having multiple
@babel/core
versions in the node_modules tree.I am still trying to work out a minimal reproduction.