Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

babeljs

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"
        ]
    ]
}
like image 875
Dr.YSG Avatar asked May 10 '19 17:05

Dr.YSG


People also ask

Does babel automatically polyfill?

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 ).

How does babel polyfill work?

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.

What is regenerator runtime min JS?

regenerator-runtime is the runtime support for compiled/transpiled async functions. (It may well have other uses, but this is the predominant one.)


2 Answers

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";
like image 67
Abu Sayem Md Habibullah Avatar answered Oct 25 '22 14:10

Abu Sayem Md Habibullah


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

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

like image 38
Dr.YSG Avatar answered Oct 25 '22 15:10

Dr.YSG