Bundled modular package requires global regeneratorRuntime
cangarugula opened this issue · comments
I have a modular package that uses async functions, which when built with modular expects a global reference of regeneratorRuntime, which cannot be found.
node dist-cjs/service.cjs.js
[ERR] var _ref = _asyncToGenerator( /#PURE/regeneratorRuntime.mark(function _callee(uuid) {
[ERR] ^
[ERR] ReferenceError: regeneratorRuntime is not defined
This is happening because we are not setting targets for the @babel/preset-env preset when bundling with rollup for non "app" type modular apps.
One patch I've found is to set target.esmodules to true for @babel/preset-env. This is not a permanent solution as setting esmodules will override browserlists which may be an issue when bundling a view.
[ '@babel/preset-env', { targets: { esmodules: true } } ]
[ '@babel/preset-env', { targets: { esmodules: true } } ]
I think this is a fine workaround for now - I noticed this also improved the output size of our bundles. Given the wide availability of esmodule targets I think it's fine to start targeting this. I've raised a PR in #366 .
Sounds good!