npm i --save-dev @babel/plugin-transform-runtime
{
"plugins": ["@babel/plugin-transform-runtime"]
}
More Info: https://babeljs.io/docs/en/babel-plugin-transform-runtime
TLDR;
Thanks It works when I add an import statement -- import regeneratorRuntime from "regenerator-runtime";
in the component i am using async/await.
Ran into this problem (using Babel v7) and even after following the advice and installing relevant packages, I was still unable to get id of this error. following stack overflow posts were checked...
Following actions helped:
"moduleNameMapper": {
".+\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "identity-obj-proxy" }
--setupFilesAfterEnv "./src/setupTests.js"
so to run a test, it will be:
$ jest /pathToTest/TestFile.test.js --setupFilesAfterEnv "./src/setupTests.js"
Hope it helps someone like it helped me...
If it's really necessary for you to use the async function then the solutions above should work. Another way to resolve this is to use regular promises, at least that was in my case.
just add
"browserslist": [
"last 2 Chrome versions"
]
at the end of your projects package.json
file, also see that its plural browsers not browser!
Your file in the end might look something like this ->
},
"dependencies": {
"prop-types": "^15.8.0",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"browserslist": [
"last 2 Chrome versions"
]
}
ignore the dependency section in the above code view, its just for reference on how your package.json might look.
2022
If you're working with Babel 7 or later version, you don't need to install an extra plugin (neither @babel/plugin-transform-runtime
or @babel/plugin-transform-regenerator
or other plugins ).
Later, you have to include this statement every time you're using async/await
syntax.
import regeneratorRuntime from "regenerator-runtime";
Maybe if you have set a linter in your project it will warning you about that statement is declared but its value is never read, but I think is just an error, because if you delete it the code doesn't work.
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.