Skip to content

regeneratorRuntime is not defined when using generator #708

Closed

Description

@domoritz
{
  "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).

Activity

  1. developit commented on Aug 22, 2020

    @developit
    Owner

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

  2. domoritz commented on Aug 22, 2020

    @domoritz
    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).

  3. domoritz commented on Aug 22, 2020

    @domoritz
    Author

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

  4. developit commented on Aug 23, 2020

    @developit
    Owner

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

  5. domoritz commented on Aug 23, 2020

    @domoritz
    Author

    Sweet. Thanks!

  6. yovanoc commented on Dec 2, 2020

    @yovanoc

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

  7. domoritz commented on Dec 2, 2020

    @domoritz
    Author
  8. added
    has-fixA fix is available, but may not yet be released.
    and removed on Dec 18, 2020
  9. added this to the 0.13.0 milestone on Dec 18, 2020
  10. developit commented on Dec 18, 2020

    @developit
    Owner

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

  11. jackmoxley commented on Mar 19, 2021

    @jackmoxley

    This is happening for me in 0.13.0

  12. eatsjobs commented on May 18, 2021

    @eatsjobs

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

  13. developit commented on Jun 3, 2021

    @developit
    Owner

    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.

  14. YousefED commented on Jul 27, 2021

    @YousefED

    @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

  15. developit commented on Jul 27, 2021

    @developit
    Owner

    @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).

  16. YousefED commented on Jul 27, 2021

    @YousefED

    @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.

  17. YousefED commented on Aug 17, 2021

    @YousefED

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-fixA fix is available, but may not yet be released.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions