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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot read properties of undefined (reading 'addHelper') #15752

Closed
1 task
ethanyou725 opened this issue Jul 6, 2023 · 38 comments
Closed
1 task

[Bug]: Cannot read properties of undefined (reading 'addHelper') #15752

ethanyou725 opened this issue Jul 6, 2023 · 38 comments
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@ethanyou725
Copy link

ethanyou725 commented Jul 6, 2023

馃捇

  • 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

@babel-bot
Copy link
Collaborator

Hey @ethanyou725! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@alan-agius4
Copy link

alan-agius4 commented Jul 6, 2023

With the recent release we also received similar reports in Angular CLI for path.hub.file. See: angular/angular-cli#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.

@cixiu
Copy link

cixiu commented Jul 6, 2023

same question.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 6, 2023

Working on it :) (investigating)

@nicolo-ribaudo
Copy link
Member

As a workaround, try using resolutions to pin to an older @babel/traverse version.

@nandeshwarshubh
Copy link

We are facing the same issue. Downgrading to previous version worked!

@xdoer
Copy link

xdoer commented Jul 6, 2023

same issue

@deshpandekshitij
Copy link

deshpandekshitij commented Jul 6, 2023

Overriding @babel/traverser to last version worked for us
Add this to package.json
"overrides": {
"@babel/traverse": "7.22.6"
},

@xdoer
Copy link

xdoer commented Jul 6, 2023

As a workaround, try using resolutions to pin to an older @babel/traverse version.

it works, thanks

@nicolo-ribaudo
Copy link
Member

I have not found the cause of the bug yet, but #15754 should probably make it away until when I figure out how to properly fix it.

@Tofandel
Copy link

Tofandel commented Jul 6, 2023

The problem lies in the dependency tree, likely in preset env which is not pinning some sub dependencies and using a range resulting in some mismatched versions of the babel plugins, so basically you have for instance the @babel/plugin-syntax-object-rest-spread at version 7.22.7 but you pinned @babel/core at 7.17.9, so there is a mismatch in the feature set

I think the solution is to mark in the @babel/traverse package a peer dependency of @babel/core: ">7.22.0"

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 6, 2023

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.

@alan-agius4
Copy link

Thank you @nicolo-ribaudo.

@nicolo-ribaudo
Copy link
Member

@Tofandel That shouldn't cause problems. In the angular issue linked above, there is only one version of @babel/core and @babel/traverse but it still errors.

@Tofandel
Copy link

Tofandel commented Jul 6, 2023

Well I had the error and then when I upgraded all the babel packages, no more error

So I'd like to see an npm why @babel/traverse or npm why @babel/core in your project

@drrastafarai
Copy link

Thank you!
@nicolo-ribaudo

@Vrq
Copy link

Vrq commented Jul 6, 2023

We are facing the same issue while using react-scripts.

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?

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 6, 2023

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.

@Tofandel
Copy link

Tofandel commented Jul 6, 2023

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

@nicolo-ribaudo
Copy link
Member

Can anyone still reproduce the problem with @babel/core and @babel/traverse 7.22.8, or can I close this issue?

If you can still reproduce the issue using those versions, could you share a repository (even if not minimal) I can use to reproduce it?

@JeanMeche
Copy link

JeanMeche commented Jul 6, 2023

I can confirm that the issue on angular has been fix with the update 馃憤

Thank you @nicolo-ribaudo for the swift fix !

@FareedGuru
Copy link

Hi @nicolo-ribaudo,
this is my package.json related to babel:
"dependencies": {
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
"@babel/polyfill": "7.4.3",
"babel-polyfill": "6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
}
"devDependencies": {
"@babel/cli": "7.14.8",
"@babel/core": "7.22.8",
"@babel/plugin-proposal-class-properties": "7.4.0",
"@babel/plugin-syntax-dynamic-import": "7.2.0",
"@babel/plugin-transform-modules-commonjs": "7.4.3",
"@babel/plugin-transform-react-constant-elements": "7.2.0",
"@babel/plugin-transform-react-inline-elements": "7.2.0",
"@babel/preset-env": "7.4.3",
"@babel/preset-react": "7.0.0",
"@babel/register": "7.4.0",
}

i am facing the issue, can you tell me the exact versions to fixed ?

@Tofandel
Copy link

Tofandel commented Jul 6, 2023

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

@riddhi-24
Copy link

@nicolo-ribaudo
Yes I am still facing issue with react project
image

Build fail
image

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 6, 2023

@riddhi-24 Can you make sure that your lockfile does not contain @babel/core or @babel/traverse 7.22.7 (delete them if they are there), and then re-run npm install? Also, I strongly recommend not pinning to a version of @babel/core that old (7.1.2) :)

@riddhi-24
Copy link

Yes, actually I've removed @babel/core & tried everything seems working as expected

@IhorShmidt
Copy link

I had the same issue, and after upgrading babel to version 7.22.8, I have now another issue
An unhandled exception occurred: Call retries were exceeded
Does anyone know how to fix it?

@Tofandel
Copy link

Tofandel commented Jul 6, 2023

On everybody affected by the issue, are any of you using npm or are you all using yarn ?

Here is a bug I've noticed with yarn when pinning dependencies and running yarn install it duplicates dependencies (it's only when running yarn install, when running yarn upgrade the issue gets fixed)

https://github.com/Tofandel/renovate_yarn_bug/pull/2/files

@nicolo-ribaudo
Copy link
Member

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

@ethanyou725
Copy link
Author

Thanks @nicolo-ribaudo. Build was passed with new version

@tanzgr8
Copy link

tanzgr8 commented Jul 7, 2023

Thanks @nicolo-ribaudo Yesterday I faced same issue while production deployment. With the latest version it seems to be working fine now

@mendrixsebas
Copy link

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
Copy link
Member

Could you share your package.json, Babel config, and lockfile?

@mendrixsebas
Copy link

Could you share your package.json, Babel config, and lockfile?

I narrowed it down to "@react-native/metro-config": "^0.72.11", being upgraded to ^0.73.0 in my package.json, but that is still a nightly so we can ignore this for now.

This happened because I used npm-check-updates with ncu -u --target minor

@mgithubmessier
Copy link

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"
  },

@SidneyLann
Copy link

error src\view\LegenImage.tsx: D:\DEV\eb_app\src\view\LegenImage.tsx: Cannot read properties of undefined (reading 'addHelper').
TypeError: D:\DEV\eb_app\src\view\LegenImage.tsx: Cannot read properties of undefined (reading 'addHelper')
at wrapInterop (D:\DEV\eb_app\node_modules@babel\helper-module-transforms\src\index.ts:198:41)
at PluginPass.call (D:\DEV\eb_app\node_modules@babel\plugin-transform-modules-commonjs\src\index.ts:255:28)
at call (D:\DEV\eb_app\node_modules@babel\traverse\src\visitors.ts:270:14)
at NodePath._call (D:\DEV\eb_app\node_modules@babel\traverse\src\path\context.ts:35:20)
at NodePath.call (D:\DEV\eb_app\node_modules@babel\traverse\src\path\context.ts:20:17)
at NodePath.visit (D:\DEV\eb_app\node_modules@babel\traverse\src\path\context.ts:112:8)
at TraversalContext.visitQueue (D:\DEV\eb_app\node_modules@babel\traverse\src\context.ts:144:16)
at TraversalContext.visitSingle (D:\DEV\eb_app\node_modules@babel\traverse\src\context.ts:108:19)
at TraversalContext.visit (D:\DEV\eb_app\node_modules@babel\traverse\src\context.ts:176:19)
at traverseNode (D:\DEV\eb_app\node_modules@babel\traverse\src\traverse-node.ts:34:17)
at traverse (D:\DEV\eb_app\node_modules@babel\traverse\src\index.ts:75:15)
at transformFile (D:\DEV\eb_app\node_modules@babel\core\src\transformation\index.ts:120:13)
at transformFile.next ()
at run (D:\DEV\eb_app\node_modules@babel\core\src\transformation\index.ts:47:12)
at run.next ()
at D:\DEV\eb_app\node_modules@babel\core\src\transform-ast.ts:34:20
at Generator.next ()
at evaluateSync (D:\DEV\eb_app\node_modules\gensync\index.js:251:28)
at fn (D:\DEV\eb_app\node_modules\gensync\index.js:89:14)
at stopHiding - secret - don't use this - v1 (D:\DEV\eb_app\node_modules@babel\core\src\errors\rewrite-stack-trace.ts:97:14)
at transformFromAstSync (D:\DEV\eb_app\node_modules@babel\core\src\transform-ast.ts:77:59)
at Object.transform [as nextTransformer] (D:\DEV\eb_app\node_modules\metro-react-native-babel-transformer\src\index.js:199:20)
at Object.transform (D:\DEV\eb_app\node_modules@tarojs\rn-transformer\src\index.ts:44:18)
at D:\DEV\eb_app\node_modules@tarojs\rn-supporter\src\taroTransformer.ts:59:51
at Generator.next ()

Same issue for
"resolutions": {
"@babel/traverse": "7.22.20",
"@babel/core": "7.22.20"
},

@TarifEzaz
Copy link

I had to install to version 0.72.5 to resolve this issue.

@SidneyLann
Copy link

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

this not work for me

zatteo added a commit to zatteo/react-native-cameraroll that referenced this issue Nov 17, 2023
@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 Feb 10, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests