question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

Async functions are always transformed to regenerator runtime

See original GitHub issue

๐Ÿ› bug report

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

Without config just do

yarn init
yarn add parcel-bundler

create index.js:

(async function () { return await 1 })()
parcel index.js

๐Ÿค” Expected Behavior

Without any babel config I would assume no transformation will be made, just bundling into one file.

๐Ÿ˜ฏ Current Behavior

Dist file will contain

_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
...

๐Ÿ’ Possible Solution

๐Ÿ”ฆ Context

In specific project async functions are transformed no matter what .babelrc I try. I am trying to migrate from browserify but using

node_modules/.bin/parcel build ./src/client/index.js --out-dir ./public --out-file bundle.js --no-minify

will give me code with async functions transformed, where

node_modules/.bin/browserify ./src/client/index.js -o ./public/bundle.js -t [ babelify ]

will keep async functions unchanged. I would expect these to behave the same in regards to babel transforms.

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

Software Version(s)
Parcel 1.6.2
Node v8.1.4
npm/Yarn 1.3.2
Operating System Mac

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:34
  • Comments:37 (4 by maintainers)

github_iconTop GitHub Comments

95reactions
brandiqacommented, Mar 3, 2018

Found this solution:

npm install --save-dev babel-plugin-transform-runtime babel-runtime

Create .babelrc file and add:

{
    "plugins": [
        ["transform-runtime",
        {
            "polyfill": false,
            "regenerator": true
        }]
    ]
}
69reactions
AbeEstradacommented, Feb 23, 2018

I was getting this error when using async/await: ReferenceError: regeneratorRuntime is not defined

My solution was adding: import "babel-polyfill";

Leaving this comment for reference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

regeneratorRuntime when using Sync/Await - Stack Overflow
I'm getting the following error when using Async/Await for functions: Uncaught ReferenceError ...
Read more >
How to fix regeneratorRuntime is not defined?
First, I found this solution: add import "babel-polyfill"; at the top of the file that you are using the async function. BUT.
Read more >
babel/polyfill
Babel includes a polyfill that includes a custom regenerator runtime and core-js. This will emulate a full ES2015+ environment (no < Stage 4...
Read more >
Regenerator Runtime is not defined - Risan Bagja
browserslistrc file finally support this async function. But because we explicitly import the regenerator-runtime , this module will always beย ...
Read more >
cypress-io/cypress - Gitter
@go-oleg You've configured the syntax-async-functions and transform-regenerator babel plugins and require('babel-polyfill') in your test code?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found