babel-loader: Module build failed: TypeError: this.setDynamic is not a function
I’m submitting a bug report
Webpack Version: 3.10.0
Babel Core Version: 7.0.0-beta.36
Babel Loader Version: 8.0.0-beta.0
Please tell us about your environment: Windows 10
{
{
"presets": ["@babel/preset-es2015",[
"@babel/preset-env", {
"target": {
"browsers": [
"last 2 versions",
"safari >= 7"
]
}
}
], "@babel/preset-react"],
"plugins": [
["transform-runtime", {
"polyfill": true,
"regenerator": true
}],
"transform-decorators-legacy",
"transform-class-properties",
"@babel/plugin-proposal-object-rest-spread",
["module-resolver", {
"root": ["./src"],
"alias": {
"styles": "./styles"
}
}]
],
"env": {
"test": {
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
]
}
}
}
}
Current behavior:
Module build failed: TypeError: this.setDynamic is not a function
at PluginPass.pre (C:\proj\src\login\node_modules\babel-plugin-transform-runtime\lib\index.js:31:12)
at transformFile (C:\proj\src\login\node_modules\@babel\core\lib\transformation\index.js:97:25)
at runSync (C:\proj\src\login\node_modules\@babel\core\lib\transformation\index.js:35:3)
at transformSync (C:\proj\src\login\node_modules\@babel\core\lib\transform-sync.js:15:38)
at Object.transform (C:\proj\src\login\node_modules\@babel\core\lib\transform.js:20:65)
at transpile (C:\proj\src\login\node_modules\babel-loader\lib\index.js:55:20)
at Object.module.exports (C:\proj\src\login\node_modules\babel-loader\lib\index.js:179:20)
Fix Removing this part of the .babelrc
"plugins": [
["transform-runtime", {
"polyfill": true,
"regenerator": true
}],
stops this error from happening but instead yields
Login.jsx?f401:32 Uncaught ReferenceError: regeneratorRuntime is not defined
in the browser
This is the babel-loader config
test: /\.jsx?$/,
exclude: /(node_modules|bower_components|public\/)/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-es2015','@babel/preset-env', "@babel/preset-react"]
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 36
- Comments: 23 (5 by maintainers)
If you’re using Babel 7’s Beta, you’ll need to install and use the Babel 7 version of the plugins too, e.g.
I had the same problem. Solved by uninstalling babel-plugin-transform-runtime, and installing @babel/plugin-transform-runtime instead.
I also needed to install @babel/runtime when using this plugin because of some error in helper libraries.
My .babelrc file now looks like this:
What really helped a lot was this resource: babel-plugin-transform-runtime
I hope this information helps you as much as it helped me.
@kousherAlam As mentioned above in https://github.com/babel/babel-loader/issues/560#issuecomment-362871436, if you’re using Babel 7, then
"@babel/plugin-transform-runtime"
is the correct plugin to use.{ // “plugins”: [“transform-runtime”,“dynamic-import-node”], “plugins”: [“@babel/plugin-transform-runtime”,“dynamic-import-node”], “presets”: [“@babel/preset-env”,“@babel/preset-react”] }
The comments is my fault config of .babelrc,you should upgrade “transform-runtime” to “@babel/plugin-transform-runtime”
still have the problem …
In a Nuxt project of mine hat worked for me — following this advice — was
followed by
nuxt build
andnuxt start
— rather thannpm run dev
which is equivalent tonuxt
.Why this works I have no idea. This problem seems to crop up in projects generated with
npx
oryarn
«create a Nuxt app» scaffolds.@Vadorequest apparently
@babel/transform-runtime
does not exit on npm.Im having a similar problem Babel Version: 7.0.0-beta.36
babelrc
Its new in Babel 7(.4) that you can shorten the names by
plugins-
andpreset-
. I think@babel/
ist now also unnecessary.@babel/transform-runtime
is the same as@babel/plugin-transform-runtime
.For babel 7 yeah this
https://babeljs.io/docs/en/babel-plugin-transform-runtime