Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regeneratorRuntime is not defined when using generator #708

Closed
domoritz opened this issue Aug 22, 2020 · 15 comments
Closed

regeneratorRuntime is not defined when using generator #708

domoritz opened this issue Aug 22, 2020 · 15 comments
Labels
has-fix A fix is available, but may not yet be released.
Milestone

Comments

@domoritz
Copy link

{
  "name": "out",
  "source": "index.js",
  "dependencies": {
    "microbundle": "^0.12.3"
  }
}
function *hello() {
    return 42
}

console.log(hello())

running

$ yarn
$ yarn microbundle
$ node node dist/out.js

Results in this error

/Users/dominik/Code/microbundle-async/dist/out.js:1
var r=regeneratorRuntime.mark(e);function e(){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",42);case 1:case"end":return r.stop()}},r)}console.log(e());
      ^

ReferenceError: regeneratorRuntime is not defined
    at Object.<anonymous> (/Users/dominik/Code/microbundle-async/dist/out.js:1:7)
    at Module._compile (internal/modules/cjs/loader.js:1251:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
    at Module.load (internal/modules/cjs/loader.js:1100:32)
    at Function.Module._load (internal/modules/cjs/loader.js:962:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

It works if I add import 'regenerator-runtime/runtime'; to the top of the js file but it would be great if I didn't have to guess that this extra import is required (and it won't be required in the modern build for example: node dist/out.modern.js works).

@developit
Copy link
Owner

developit commented Aug 22, 2020

This is a bug. I think it should be fixed by #707.

To clarify - are you using microbundle --target node? Or do you have a Babel config (.babelrc, babel.config.js, "babel" package.json field)?

@developit developit added the needs more info Needs more information label Aug 22, 2020
@domoritz
Copy link
Author

Thanks for the quick response.

To clarify - are you using microbundle --target node?

I am trying to move https://github.com/vega/vega over to microbundle and mainly target browsers. I ran into the problem above because of https://github.com/vega/vega/blob/a8e6991411c2c5c4805320f87276e9861e80d69c/packages/vega-statistics/src/numbers.js#L1.

Or do you have a Babel config (.babelrc, babel.config.js, "babel" package.json field)?

We do have a babel config in the repo (although I will probably get rid of it once I have switched over to microbundle). I was able to reproduce the issue without any special files (just the code above).

@domoritz
Copy link
Author

So yeah, my issue is similar to #704 but I am not targeting node.

@developit
Copy link
Owner

Alrighty. I need to double-check my fix there for the browser target.

@domoritz
Copy link
Author

domoritz commented Aug 23, 2020

Sweet. Thanks!

@yovanoc
Copy link

yovanoc commented Dec 2, 2020

@domoritz @developit Same error for me, there is a fix now?

@domoritz
Copy link
Author

domoritz commented Dec 2, 2020

I created my own rollup config: https://github.com/vega/vega/blob/master/rollup.config.js.

@developit developit added has-fix A fix is available, but may not yet be released. and removed needs more info Needs more information labels Dec 18, 2020
@developit developit added this to the 0.13.0 milestone Dec 18, 2020
@developit
Copy link
Owner

Fixed in 0.13. Please re-open if this is not working still.

@jackmoxley
Copy link

This is happening for me in 0.13.0

@eatsjobs
Copy link

Still have this error :( there's a patch for this behaviour?

@developit
Copy link
Owner

developit commented Jun 3, 2021

Hmm - do you have a custom Babel configuration by chance? Microbundle should be generating code that targets Node 12+, which should never use Regenerator since generators are fully supported.

@YousefED
Copy link

@developit I'm running into the same issue with the latest version, without having any custom Babel configuration.

Steps to reproduce:

npm install
npm run update
npm run build

In the output files (dist), you'll notice several references to regeneratorRuntime

@developit
Copy link
Owner

developit commented Jul 27, 2021

@YousefED your package.json has a browserslist configuration that is causing regenerator to be referenced. Specifically, the >0.2% clause will include obscure browsers for which caniuse/browserslist data is known to be incorrect, like QQ Browser and UC Browser (both of which have been Chrome/Webview-based for many years, but the compat data is based on 2016 tests).

@YousefED
Copy link

@YousefED your package.json has a browserslist configuration that is causing regenerator to be referenced. Specifically, the >0.2% clause will include obscure browsers for which caniuse/browserslist data is known to be incorrect, like QQ Browser and UC Browser (both of which have been Chrome/Webview-based for many years, but the compat data is based on 2016 tests).

Ah thanks, I think that originated from React defaults from a different project. In any case, when I remove that from package.json, I still have the same issue.

@YousefED
Copy link

YousefED commented Aug 17, 2021

@developit Not sure if you've seen my comment / would you prefer me to open a new issue? Let me know if there's any other way I help diagnose (or some hints to debug the issue myself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-fix A fix is available, but may not yet be released.
Projects
None yet
Development

No branches or pull requests

6 participants