I have a Typescript/React app, that can perform async function with a then/catch promise, but not with async/await/try/catch.
The error is: Uncaught ReferenceError: regeneratorRuntime is not defined .
The error seems to come from Babel. Here is my config:
JavaScript
x
8
1
{
2
"presets": [
3
"@babel/preset-env",
4
"@babel/preset-typescript",
5
"@babel/preset-react"
6
],
7
"plugins": ["babel-plugin-styled-components"]
8
}
How to fix this?
Advertisement
Answer
You can find your solution at here
If I summarise then you have to install a babel
plugin named plugin-transform-runtime
and need to configure the .babelrc
settings.
JavaScript
1
3
1
npm install @babel/plugin-transform-runtime --save-dev
2
npm install @babel/runtime
3
After installing these two go to the .babelrc
file and add these plugins.
JavaScript
1
8
1
"plugins": [
2
["@babel/plugin-transform-runtime",
3
{
4
"regenerator": true
5
}
6
]
7
],
8