Parcel: Assume async js functions are supported if no browserslist is specified

Created on 1 Mar 2018  路  12Comments  路  Source: parcel-bundler/parcel

Choose one: 馃檵 feature request

馃 Expected Behavior

  1. Create and use an async js function.
  2. parcel build file.js
  3. Works as intended.

馃槸 Current Behavior

  1. Create and use an async js function.
  2. parcel build file.js
  3. Get ReferenceError: regeneratorRuntime is not defined

馃拋 Possible Solution

If no browserslist is specified, assume async functions are supported if used.

馃敠 Context


Until I searched the specified note on the parcel website, I didn't know I needed to import the babel-polyfill module and/or specify browserslist in package.json

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel |1.6.2
| Node |9.5.0
| Yarn |1.5.1
| Operating System | win x64

Feature

Most helpful comment

Or at least give a good terminal warning with a suggested fix, rather than having "regeneratorRuntime is not defined" shown in the browser console.

All 12 comments

Or at least give a good terminal warning with a suggested fix, rather than having "regeneratorRuntime is not defined" shown in the browser console.

Yes please! Took me hours to figure out the problem! I'm currently writing a Chrome extension where I can expect users to use a new version with async/await support.

I get the error even with babel.

Not sure if this should be fixed as we currently set a default to browserlist that doesn't assume async is support (as it includes IE11).

We could however probably document this properly?

Perhaps we could install the polyfill by default though (if async is used)?

Meet the same error in latest browser.

Add import 'babel-polyfill' in entry file works temporarily.

@Jancat temporarily?

You can stop supporting IE, by changing the browserfield in package.json or created a browserlist config. Than it should work without polyfill.

If the polyfill is causing any issues that might be a problem with the polyfill and should be filled in the Babel repo, but I guess this wasn't what you meant?

@DeMoorJasper I'm building an H5 app and targeting moder mobiles. I set the browserslist field in package.json

"browserslist": [
    "Android >= 6.0",
    "iOS >= 10.3"
  ]

The Async functions support __Android 5, iOS 10.3 and Chrome 42__ in caniuse

But I debug in latest Chrome(v67) and the console throw the regeneratorRuntime error:

Uncaught ReferenceError: regeneratorRuntime is not defined

I had to import 'babel-polyfill to make it works.

That's strange perhaps that's a bug from Babel, not sure why this is happening @Jancat

@DeMoorJasper From Babel? But I use TypeScript in my project, no Babel except the babel-polyfill.

Is bug from Parcel TypeScript loader?

Parcel runs the javascript output from TS through babel to fit the browserlist

Using 1.9.7 I was able to fix this by adding the following to our package.json:

  "browserslist": [
    "last 1 Chrome version"
  ]

This stopped it from doing the incomplete transpilation on the async/await functions.
Hope this helps.

This is never gonna happen, as far as I know changing the default value dynamically isn't a good idea.

This will cause nasty side-effects, require lot's of documentation, cause issues and people still rely on old browsers.

Gonna close this issue as it will never get fixed.

Note: Once Babel 7 support lands we'll try to use useBuiltins for preset-env, so this error will never occur as it will just bundle in the polyfills automatically.

Was this page helpful?
0 / 5 - 0 ratings