parcel: Uncaught ReferenceError: regeneratorRuntime
š bug report
Iam trying to import and export a class from a module and i get this behavior. Every time iam trying to import the class or export it i get regeneratorRuntime .
š Configuration (.babelrc, package.json, cli command)
{
"name": "cooking-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^13.0.0",
"eslint-plugin-import": "^2.13.0"
},
"dependencies": {
"animate.css": "^3.6.1",
"axios": "^0.18.0"
}
}
š¤ Expected Behavior
Just import/export the class to the index.js
šÆ Current Behavior
Instead of import/export the class i get the follow error :
js\models\foodSearch.js:6 Uncaught ReferenceError: regeneratorRuntime is not defined at js\models\foodSearch.js:6 at js\models\foodSearch.js:12 at Object.parcelRequire.js\models\foodSearch.js.axios (js\models\foodSearch.js:12) at newRequire (js.ee4a09a9.js:48) at localRequire (js.ee4a09a9.js:54) at Object.parcelRequire.js\index.jsā¦/models/famousChefQuotes (js\index.js:3) at newRequire (js.ee4a09a9.js:48) at parcelRequire.js\models\famousChefQuotes.js (js.ee4a09a9.js:80) at js.ee4a09a9.js:106
ā¦......\AppData\Roaming\npm\node_modules\parcel-bundler\node_modules\util-deprecate\browser.js:14 Uncaught ReferenceError: regeneratorRuntime is not defined at ā¦......\AppData\Roaming\npm\node_modules\parcel-bundler\node_modules\util-deprecate\browser.js:14 at ā¦......\AppData\Roaming\npm\node_modules\parcel-bundler\node_modules\util-deprecate\browser.js:41 at Object.parcelRequire.js\models\SearchFood.js.axios (ā¦......\AppData\Roaming\npm\node_modules\parcel-bundler\node_modules\util-deprecate\browser.js:45) at newRequire (js.ee4a09a9.js:48) at localRequire (js.ee4a09a9.js:54) at Object.parcelRequire.js\index.jsā¦/models/famousChefQuotes (js\index.js:3) at newRequire (js.ee4a09a9.js:48) at parcelRequire.js\models\famousChefQuotes.js (js.ee4a09a9.js:80) at js.ee4a09a9.js:106
š» Code Sample
https://gist.github.com/Clickys/dd0d2ef946b15b0bf34b1ac23ecab3e0
š Your Environment
±- animate.css@3.6.1 ±- axios@0.18.0 ±- eslint@4.19.1 ±- eslint-config-airbnb-base@13.0.0 `-- eslint-plugin-import@2.13.0 parcel latest: ā1.9.7ā
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 37
- Comments: 69 (18 by maintainers)
Commits related to this issue
- Fix parcel not supporting async functions out-of-the-box https://github.com/parcel-bundler/parcel/issues/1762 — committed to dtinth/remark-lint-thai by dtinth 5 years ago
This works for me. Just config
.babelrcasIām quite confused. I just tried parcel with Typescript and got the same error, but Typescript itself can already transform all code, why use Babel when?
To babel7 users (Parcel >= 1.10.0):
@Timespace7
Can avoid adding
.babelrcby just adding this to yourpackage.json(babel automatically picks it up)EDIT: just noticed other people had mentioned browserslist too, but didnāt see the actual code (for anyone looking for a quick solution)
Adding regenerator-runtime solved the problem for me.
In Parcel 2, weāll apply polyfills automatically where needed using Babel 7ās
useBuiltIns: usageoption. See https://babeljs.io/docs/en/babel-preset-env#usebuiltins-usage-experimental.This would be a breaking change for Parcel 1 to do this automatically, so weāre waiting for Parcel 2.
Shouldnāt at least parcel should understand what
asyncmeans and load the regeneratorRuntime?I still have this issue with parcel 2 alpha 3.2 and with a properly set
browserslistand only onbuild.serveworks fine.Thank you! Seems like there should be clear instructions on this. I tried three solutions before one worked.
See the second to last comment in https://github.com/parcel-bundler/parcel/issues/3012 Which talks about adding
To the browserlist in package.json. That fixed this for me. keeps out the runtime.
By default parcel uses babel to transpile your code. If you use promised or async/await babel will polyfill it. But as you do not provide a polyfill get an error.
To fix this add a
.babelrcfile to the root of your project. You will find the right configuration by googleing something like ābabel no runtimeGeneratorā.Install
babel-polyfilland require it at the endpoint of your application, treeshaking should probably take care of trimming it down to as minimal of a polyfill as possible (once treeshaking is stable)This is definitely still a problem.
One solution is using this babelrc (Parcel 2):
Iāll investigate why we arenāt doing this by defaultā¦
Hello, Iām experiencing the same issue today and I wish that Parcel detects the need of whatever polyfill required by itself just like it does for everything else, and, by doing so, preserving 0-config comfort. Thanks !
Thanks @balazs4!
This is what babel recommends!
https://babeljs.io/docs/en/babel-polyfill
Facing this exact same issue now!
Quite frustrating, because parcel seems to do everything else smartly! Im going with promises as of now, as async/await seems to not work with parcel
Sorry, so how do I use async/await with a fresh parcel project? Iām targeting the latest browsers so Iād rather not include a polyfill if I donāt need to.
following babelās docs solved my problem https://babeljs.io/docs/en/babel-plugin-transform-runtime
Whenever using
.babelrcwith parcel@next on my typescript project I now get parsing error on serve and build. Whatās the actual workaround to this? I donāt think importing transpile-focused libraries into my appās codebase makes too much sense as this should be more of a configuration option in the bundler.With that said I now have an app that works nicely locally with
parcel serve(without.babelrc) but doesnāt run on production when usingparcel builddue to the missingregeneratorRuntime. And thinking this wasnāt an issue at all with Typescript any more š¦update
I have managed to include regeneratorRuntime by simply setting the
browserlistproperty on mypackage.jsonto something like"Chrome 70", as follows:However, I donāt understand why when NOT declaring
browserslist(which then defaults to>0.25%), I still get the error even when using a modern browser with async/await support, i.e: Firefox 75 ?install latest parcel v2
npm i -g parcel@2.0.0-alpha.3.2fix this error+++
This is really broken. Parcel doesnāt look smart because of that :\
BTW, Iāve found a workaround for the issue by downgrading parcel to
1.9.7and having a.babelrc:And adding
babel-plugin-transform-runtime(6.23.0) to mypackage.jsonIt works but meeeeeh :\
@timwis You need to add a
browserslistto yourpackage.jsonfile. Little demo here.Works on Firefox, Safari, and Chrome on my machine; probably works for a few versions older as well, just no way of checking that here.
Otherwise, if you use TypeScript instead (you can just rename your files to have a
.tsextension, you donāt need to actually use TypeScript), you donāt need to add thebrowserslistat all.Hi! Running into this too. After checking all possible solutions Iāve got to the following working combination. Minimal reproducible code below (sorry, couldnāt figure out how to replicate this on codesandbox):
Expand
package.jsonIām using
nightly.520as itās the latest one that works for me (522+ produces some issues with promises Iām not ready to handle) and it has fixed vulnerabilities present inbeta.1- but result should be the same for it too.index.jsSteps to make it work:
package.json:npm -i -D @parcel/babel-plugin-transform-runtime- babel config needs itimport 'regenerator-runtime/runtime';to theindex.js(specific file with broken component works too)For me, it wasnāt enough to have only the babel config or the import alone - I had to add both. Otherwise, the error persists. Hope this helps š
With Parcel 2, if you do specify a babel config, Parcel wonāt amend it, so you probably need:
@devongovett @DeMoorJasper I am using the latest parcel 2 and still encountering this issue. I tried adding the import āregenerator-runtime/runtimeā; in my index.js file but the browser is still throwing the error. Also tried adding the browserlist but still to no avail. Help please!
We should definitely do this, the only question is whether
@parcel/babel-plugin-transform-runtimecould also inject unneeded code in some situations (e.g. with if async shouldnāt be transpiled according to browserslist).@mischnic thanks a lot for the clarifications
Sorry, you should always use
@parcel/babel-preset-envbecause that one allows Parcel to forward browserslist information to the preset-env plugin.You can ignore that for now. Looks like we need to add
@babel/coreas a peer dependency here as well: https://github.com/parcel-bundler/parcel/blob/eaa0137195e101438b3784400496899c275f18e8/packages/utils/babel-plugin-transform-runtime/package.jsonWell, this ānon-issueā doesnāt happen when using other bundlers.
@KaKi87 this isnāt an issue, this is just how babel/preset-env works⦠we didnāt write that. Like I mentioned I canāt get any of these issues to happen and use the async syntax all the time.
@fab7jj you can view the v2 docs at https://v2.parceljs.org/
Yup, same issue here. That makes no sense.
@balazs4 As I said, if one is running Chromium V74+ there should be no need for the runtime. (Indeed I can use other bundlers with babel and that works without the runtime support).
@Timespace7 how come it doesnāt work with
@babel/preset-env?Thank you for answers,
By default if i want to use async/await which babel packages dependencies i should install for my project ?