microbundle: regeneratorRuntime is not defined when using generator
{
"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).
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (5 by maintainers)
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.
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)?