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
[Bug] Console error: Uncaught TypeError: Cannot set properties of undefined (setting 'default') #14628
Comments
Hey @gongshun! 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. |
same issue with React project, got the excat same issue with @babel/runtime 7.18.3 |
System: using lerna with rollup possible solution would be, if we can check first and then assign would be work
|
I'm really confused by this error. Could you open your bundle and check the source of the (outer) |
so i am, but the function is calling before excution and getting undfined default value error. |
Can you share your bundle? I don't understand how |
Are you bundling your app? That code contained in You need to find the EDIT: I see that you said that you are using rollup. You need to look at the file generated by rollup. |
so the config is as below
|
You need to check the contents of the file specified in |
Yes, it's defined at line 18 in your screenshot. Could you try disabling source maps, and check what code in that bundled file is throwing exactly? |
no, you dint understand my point, somehow while testing our application jest is throughing error Uncaught TypeError: Cannot set properties of undefined (setting 'default'), so how it can be excuted that time even not calling that function |
But that code is not trying to set any property named |
Yes, that code looks correct. We need to understand what code is throwing about default, because the source maps are pointing at the wrong code. Would you be able to push a repository that reproduces the bug? |
so as per above, seems missing with some configuration which is not correctly building. Thanks you very much to pointing this out |
Could you try removing |
also one thing notice, if using babelHelper: runtime, that time it making an issue
could this be the issue, because it not shown in the building as like below.
https://github.com/Annshuk/microfrotend-lerna/tree/main/packages/design-system/dist <- can refer this |
@gongshun Thanks, that screenshot is definitely buggy code! However, that is not the code published by us in @Annshuk How can I use your repository to see this bug? I tried running the following commands:
but all the tests passed without errors. I also tried |
The problems is with different system with same configuratio, so there when bundles creating it taking from all the errors is happening while running test, so it throwing that regeneratorRuntime error @nicolo-ribaudo any Suggestion or is this issue. |
@Annshuk I'll need a repository I can use to reproduce the bug. Unfortunately I ran out of ideas for this, I don't know what is causing the error 😅 |
@nicolo-ribaudo it works normally when I use @babel/runtime v7.17.9 |
@nicolo-ribaudo thought my bundler cjs having |
I have exactly the same issue as the issue starter. The given solution is also working on our side. The variable |
@KvanSteijn Can you provide a repository I can clone to reproduce the problem? It's imposble for us to understand what's causing the bug otherwise. |
@nicolo-ribaudo we are using React Dropdown (https://github.com/react-component/dropdown), this package used multiple other packages. One of this packages is rc-trigger. When we are compiling our code, async (https://github.com/react-component/trigger/blob/f5fb0e980698a97fce0e531a78087fc8a38b4757/src/Popup/useVisibleStatus.ts#L86 )will be transformed to _regeratorRuntime. But it's look like that this function is broken after couple of modifications. |
I'm sorry but I will need a repository. This bug is probably caused by a specific combination of different tools (Babel, webpack, terser maybe? Or other bundlers/minifiers), and without seeing how they are interacting I cannot guess what's happened. |
sameproblem,is there any solution to fix it? @nicolo-ribaudo |
Can you provide a repository I can clone to reproduce the problem? It's imposble for us to understand what's causing the bug otherwise. |
Note: from the screenshots and stack traces its clear that this is almost certainly not a Babel bug. There is some tool that you are all using that incorrectly rewrites I'm being nice and offering to help all of you for free by cloning a repository that reproduces the bug, debug it and find which tool is broken, so that we can report the bug in the correct place. However, if none of you can provide such demo that shows the bug (and I now asked for or 4 times) I'm going to close this issue and you all will have to figure out which tool is transforming the helper code incorrectly by yourself. |
Ok, lets try to make things simpler. @codeHung shows almost certainly that it's a webpack bug. Which webpack version are you using? |
@nicolo-ribaudo I have the same issue (I don't have repository I can share unfortunately). My Webpack is at version 4.4.6 if that helps - for some other reasons I'm blocked in using Webpack 5 for the time being, so its the latest 4.x I'm using. Thanks for taking the time to help us with this! |
Ohh maybe I have an idea. I found a similar Babel bug, but it shouldn't affect you if you are using However, I'll fix it and maybe it will solve this problem. It could only affect you if you are using Babel to compile ESM to CJS in webpack (you shouldn't! Webpack prefers ESM to CommonJS) and you are compiling your dependencies. |
I'll confess to not fully understanding what you said, but perhaps this config from my webpack is relevant if by CJS you mean corejs? const babelLoader = {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { useBuiltIns: 'entry', corejs: 3 }]],
compact: false,
plugins: [
'@babel/plugin-transform-async-to-generator',
'@babel/plugin-transform-arrow-functions',
'@babel/plugin-transform-modules-commonjs',
['inline-dotenv', { path: `.env.${argv.mode}`, unsafe: true }],
['import', { libraryName: 'antd', style: true }],
],
},
}; |
Sorry, CommonJS. If you delete Btw, is there any reason why you enabled |
I opened #14708 which might hopefully fix this. Babel was broken when compiling a specific For most of you, the best solution is to not transform CommonJS modules when using Rollup or Webpack, since bundlers can optimize your code better when they see the original ESM code. |
Thanks so much - this fixed the issue for me. I inherited the project so perhaps they didn't used to part of |
💻
How are you using Babel?
Other (Next.js, Gatsby, vue-cli, ...)
Input code
same as https://ask.dcloud.net.cn/question/145538.
I wrote
async/await
in the project created by vue-cli v4.5.17Configuration file name
babel.config.json
Configuration
No response
Current and expected behavior
Console error: Uncaught TypeError: Cannot set properties of undefined (setting 'default'),Then I click on the error to view the source code,I saw the code below:
QQ20220601-163039-HD.mp4
Environment
System:
OS: macOS 12.4
Binaries:
Node: 10.24.1 - ~/.nvm/versions/node/v10.24.1/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v10.24.1/bin/yarn
npm: 6.14.12 - ~/.nvm/versions/node/v10.24.1/bin/npm
npmPackages:
@babel/plugin-transform-modules-commonjs: ^7.7.5 => 7.18.2
babel-eslint: ^10.1.0 => 10.1.0
babel-plugin-import: 1.13.3 => 1.13.3
eslint: ^6.7.2 => 6.8.0
Possible solution
When I moved the code that reported the error below, it worked fine,like this:
QQ20220601-163301-HD.mp4
Additional context
it works normally when I use @babel/runtime v7.17.9
The text was updated successfully, but these errors were encountered: