I continue to get:
App.jsx:11 Uncaught ReferenceError: regeneratorRuntime is not defined
on any line that does an async. I don't what that polyfill, but I am having a hard time getting rid of it:
app.jsx:11)
const fetcher = (async () => {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"@types/react": "^16.8.17",
"babel-preset-env": "^1.7.0"
here is the .babelrc
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": ">70",
},
"exclude": ["transform-regenerator"]
},
"@babel/preset-react"
]
]
}
Babel includes a polyfill that includes a custom regenerator runtime and core-js. This will emulate a full ES2015+ environment (no < Stage 4 proposals) and is intended to be used in an application rather than a library/tool. (this polyfill is automatically loaded when using babel-node ).
Babel Polyfill adds support to the web browsers for features, which are not available. Babel compiles the code from recent ecma version to the one, which we want. It changes the syntax as per the preset, but cannot do anything for the objects or methods used.
regenerator-runtime is the runtime support for compiled/transpiled async functions. (It may well have other uses, but this is the predominant one.)
If you want to use async, await with (ES6 or ES Next) then you must need to install @babel/polyfill but you don't need to write anything in babelrc file. Just install
npm install --save @babel/polyfill
From the documentation:
Because this is a polyfill (which will run before your source code), we need it to be a dependency, not a devDependency
And finally you need to import @bable/polyfill in your mainJS (App.js) file like:
import "@babel/polyfill";
This appears to be a bug in the parcel js bundler.
https://github.com/babel/babel/issues/9971
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With