I'm getting the error Uncaught ReferenceError: regeneratorRuntime is not defined
using React with webpack and Babel .
I've followed this answer by defining my .babel.rc
as:
{
"presets": ["@babel/preset-env", "@babel/preset-react"] ,
"plugins": [
["@babel/plugin-transform-runtime"]
]
}
and running:
npm i --save-dev @babel/plugin-transform-runtime
However, I get the exact same error afterwards. I've also followed this other answer and this one , but still get the exact same error.
My babel specific installations in package.json
are as follows:
"dependencies": {
"@babel/runtime": "^7.14.6"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@babel/preset-react": "^7.14.5"
}
Any ideas?
This ended up working for me:
How to allow async functions in React + Babel?
My problem was that I was defining the babel plugin in both my .babel.rc
file and my webpack.config.js
file. I needed to remove that plugin from my webpack.config.js
and simply use it only in my .babel.rc
file. Then it worked well.
{ "presets": [ [ "@babel/preset-env", { "targets": { "node": "9.2.1" } } ], "@babel/preset-react" ] }
This is my file .babelrc
Look:
@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills ) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!
your problemes:
You are using "@ babel / preset-env" you must specify the version of node to compile. "node> 7.6". I recommend 10.
Why node > 7.6 Node.js 7.6 has shipped with official support for async/await enabled by default and better performance on low-memory devices.
How do you specify the version: It's simple
targets.node string | "current".
If you want to compile against the current node version, you can specify "node": "current", which would be the same as "node": process.versions.node.
AND FOR ME LOOK LIKE THIS:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "9.2.1"
}
}
],
"@babel/preset-react"
]
}
This allows the compiler to understand ASYNC AWAIT, hope it helps you!
hey I ran into the same problem and I am using Babel 7, for me I installed these two dependencies:
npm install --save @babel/runtime
npm install --save-dev @babel/plugin-transform-runtime
And, in .babelrc, add:
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/transform-runtime"]
]
}
and this solved my problem
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.