Sitelet https://web.archive.org/web/20201209134946/https://github.com/developit/microbundle/issues/708
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

Open
domoritz opened this issue Aug 22, 2020 · 7 comments
Open

regeneratorRuntime is not defined when using generator #708

domoritz opened this issue Aug 22, 2020 · 7 comments

Comments

@domoritz
Copy link

@domoritz domoritz commented Aug 22, 2020

{
  "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 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)?

@domoritz
Copy link
Author

@domoritz domoritz commented Aug 22, 2020

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

@domoritz domoritz commented Aug 22, 2020

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

@developit
Copy link
Owner

@developit developit commented Aug 23, 2020

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

@domoritz
Copy link
Author

@domoritz domoritz commented Aug 23, 2020 •

Sweet. Thanks!

@yovanoc
Copy link

@yovanoc yovanoc commented Dec 2, 2020

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

@domoritz
Copy link
Author

@domoritz domoritz commented Dec 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.