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

Most upvoted comments

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

"resolutions": {
    "@babel/traverse": "7.22.8",
    "@babel/core": "7.22.8"
  },

I tracked down the cause of the bug to using @babel/traverse@7.22.6 with @babel/core@7.22.5 or older.

Does anyone know how to freeze the whole dependency tree using npm so that the builds are reproducible and such issues don’t make it into production?

Use a package-lock.json/yarn.lock file, and use npm ci/yarn --frozen-lockfile instead of npm 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.

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.

"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 image

Build fail image

For the source of the issue it’s indeed to have 2 @babel/core packages

In 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
"@babel/core@7.22.7":
  version "7.22.7"
  resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.22.7.tgz#b0a766ebdb776d83981a221d90b2db887b870659"
  integrity sha512-exABdCVjEk8+IFJW0gOK6+cou8VKMXfbkLGeK5Xdsa5MsuQmem1SsnnZ+6avm2gRhZ4M7UgAnE6YoAzVg9P/pw==
  dependencies:
    "@ampproject/remapping" "^2.2.0"
    "@babel/code-frame" "^7.22.5"
    "@babel/generator" "^7.22.7"
    "@babel/helper-compilation-targets" "^7.22.6"
    "@babel/helper-module-transforms" "^7.22.5"
    "@babel/helpers" "^7.22.6"
    "@babel/parser" "^7.22.7"
    "@babel/template" "^7.22.5"
    "@babel/traverse" "^7.22.7"
    "@babel/types" "^7.22.5"
    "@nicolo-ribaudo/semver-v6" "^6.3.3"
    convert-source-map "^1.7.0"
    debug "^4.1.0"
    gensync "^1.0.0-beta.2"
    json5 "^2.2.2"
"@babel/core@^7.12.16", "@babel/core@^7.15.8":
  version "7.21.4"
  resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.21.4.tgz#c6dc73242507b8e2a27fd13a9c1814f9fa34a659"
  integrity sha512-qt/YV149Jman/6AfmlxJ04LMIu8bMoyl3RB91yTFrxQmgbrSvQMy7cI8Q62FHx1t8wJ8B5fu0UDoLwHAhUo1QA==
  dependencies:
    "@ampproject/remapping" "^2.2.0"
    "@babel/code-frame" "^7.21.4"
    "@babel/generator" "^7.21.4"
    "@babel/helper-compilation-targets" "^7.21.4"
    "@babel/helper-module-transforms" "^7.21.2"
    "@babel/helpers" "^7.21.0"
    "@babel/parser" "^7.21.4"
    "@babel/template" "^7.20.7"
    "@babel/traverse" "^7.21.4"
    "@babel/types" "^7.21.4"
    convert-source-map "^1.7.0"
    debug "^4.1.0"
    gensync "^1.0.0-beta.2"
    json5 "^2.2.2"
    semver "^6.3.0"
"@babel/traverse@^7.0.0", "@babel/traverse@^7.20.5", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.21.4":
  version "7.21.4"
  resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.21.4.tgz#a836aca7b116634e97a6ed99976236b3282c9d36"
  integrity sha512-eyKrRHKdyZxqDm+fV1iqL9UAHMoIg0nDaGqfIOd8rKH17m5snv7Gn4qgjBoFfLz9APvjFU/ICT00NVCv1Epp8Q==
  dependencies:
    "@babel/code-frame" "^7.21.4"
    "@babel/generator" "^7.21.4"
    "@babel/helper-environment-visitor" "^7.18.9"
    "@babel/helper-function-name" "^7.21.0"
    "@babel/helper-hoist-variables" "^7.18.6"
    "@babel/helper-split-export-declaration" "^7.18.6"
    "@babel/parser" "^7.21.4"
    "@babel/types" "^7.21.4"
    debug "^4.1.0"
    globals "^11.1.0"
"@babel/traverse@^7.22.5":
  version "7.22.5"
  resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.5.tgz#44bd276690db6f4940fdb84e1cb4abd2f729ccd1"
  integrity sha512-7DuIjPgERaNo6r+PZwItpjCZEa5vyw4eJGufeLxrPdBXBoLcCJCIasvK6pK/9DVNrLZTLFhUGqaC6X/PA007TQ==
  dependencies:
    "@babel/code-frame" "^7.22.5"
    "@babel/generator" "^7.22.5"
    "@babel/helper-environment-visitor" "^7.22.5"
    "@babel/helper-function-name" "^7.22.5"
    "@babel/helper-hoist-variables" "^7.22.5"
    "@babel/helper-split-export-declaration" "^7.22.5"
    "@babel/parser" "^7.22.5"
    "@babel/types" "^7.22.5"
    debug "^4.1.0"
    globals "^11.1.0"
"@babel/traverse@^7.22.6":
  version "7.22.6"
  resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.6.tgz#8f2f83a5c588251584914debeee38f35f661a300"
  integrity sha512-53CijMvKlLIDlOTrdWiHileRddlIiwUIyCKqYa7lYnnPldXCG5dUSN38uT0cA6i7rHWNKJLH0VU/Kxdr1GzB3w==
  dependencies:
    "@babel/code-frame" "^7.22.5"
    "@babel/generator" "^7.22.5"
    "@babel/helper-environment-visitor" "^7.22.5"
    "@babel/helper-function-name" "^7.22.5"
    "@babel/helper-hoist-variables" "^7.22.5"
    "@babel/helper-split-export-declaration" "^7.22.6"
    "@babel/parser" "^7.22.6"
    "@babel/types" "^7.22.5"
    debug "^4.1.0"
    globals "^11.1.0"
"@babel/traverse@^7.22.7":
  version "7.22.7"
  resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.7.tgz#68a5513f3c6b88c7b5f5825d0720fb43e8a31826"
  integrity sha512-vQn61YQzktf1wFNzCka2dynnnbmBpUDeUCds3Y+FBHZpcVxpBq0XscQGDDVN7sV2Vf1pZDY1HmPR3U/5t7VfMQ==
  dependencies:
    "@babel/code-frame" "^7.22.5"
    "@babel/generator" "^7.22.7"
    "@babel/helper-environment-visitor" "^7.22.5"
    "@babel/helper-function-name" "^7.22.5"
    "@babel/helper-hoist-variables" "^7.22.5"
    "@babel/helper-split-export-declaration" "^7.22.6"
    "@babel/parser" "^7.22.7"
    "@babel/types" "^7.22.5"
    debug "^4.1.0"
    globals "^11.1.0"

This is really a messy yarn.lock,

so I forced a rebuild using `yarn upgrade` which now merged the deps
"@babel/core@7.22.7", "@babel/core@^7.12.16", "@babel/core@^7.15.8", "@babel/core@^7.20.2":
  version "7.22.7"
  resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.22.7.tgz#b0a766ebdb776d83981a221d90b2db887b870659"
  integrity sha512-exABdCVjEk8+IFJW0gOK6+cou8VKMXfbkLGeK5Xdsa5MsuQmem1SsnnZ+6avm2gRhZ4M7UgAnE6YoAzVg9P/pw==
  dependencies:
    "@ampproject/remapping" "^2.2.0"
    "@babel/code-frame" "^7.22.5"
    "@babel/generator" "^7.22.7"
    "@babel/helper-compilation-targets" "^7.22.6"
    "@babel/helper-module-transforms" "^7.22.5"
    "@babel/helpers" "^7.22.6"
    "@babel/parser" "^7.22.7"
    "@babel/template" "^7.22.5"
    "@babel/traverse" "^7.22.7"
    "@babel/types" "^7.22.5"
    "@nicolo-ribaudo/semver-v6" "^6.3.3"
    convert-source-map "^1.7.0"
    debug "^4.1.0"
    gensync "^1.0.0-beta.2"
    json5 "^2.2.2"
"@babel/traverse@^7.20.1", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.6", "@babel/traverse@^7.22.7":
  version "7.22.7"
  resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.7.tgz#68a5513f3c6b88c7b5f5825d0720fb43e8a31826"
  integrity sha512-vQn61YQzktf1wFNzCka2dynnnbmBpUDeUCds3Y+FBHZpcVxpBq0XscQGDDVN7sV2Vf1pZDY1HmPR3U/5t7VfMQ==
  dependencies:
    "@babel/code-frame" "^7.22.5"
    "@babel/generator" "^7.22.7"
    "@babel/helper-environment-visitor" "^7.22.5"
    "@babel/helper-function-name" "^7.22.5"
    "@babel/helper-hoist-variables" "^7.22.5"
    "@babel/helper-split-export-declaration" "^7.22.6"
    "@babel/parser" "^7.22.7"
    "@babel/types" "^7.22.5"
    debug "^4.1.0"
    globals "^11.1.0"

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/25496

The 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.