Dr.YSG
Dr.YSG

Reputation: 7591

regeneratorRuntime is not defined (how keep babel from including that polyfill?)

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"
        ]
    ]
}

Upvotes: 12

Views: 10952

Answers (2)

As Md Habibullah
As Md Habibullah

Reputation: 361

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";

Upvotes: 13

Dr.YSG
Dr.YSG

Reputation: 7591

This appears to be a bug in the parcel js bundler.

https://github.com/babel/babel/issues/9971

Upvotes: 3

Related Questions