microbundle
microbundle copied to clipboard
async/await is always transpiled into regenerator even with browserconfig or babelrc
How to reproduce error
Execute this script in an empty directory
#!/bin/bash
cat > index.js <<< 'export function* yo() { yield 1 }'
cat > package.json <<'EOF'
{
"name": "a",
"devDependencies": {
"microbundle": "0.12.3"
},
"browserslist": [
"last 2 Chrome versions"
]
}
EOF
yarn
yarn microbundle --no-compress
cat dist/a.js
Expected resut
function* yo() {
yield 1;
}
exports.yo = yo;
//# sourceMappingURL=a.js.map
Actual result
var _marked = /*#__PURE__*/regeneratorRuntime.mark(yo);
function yo() {
return regeneratorRuntime.wrap(function yo$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return 1;
case 2:
case "end":
return _context.stop();
}
}, _marked);
}
exports.yo = yo;
//# sourceMappingURL=a.js.map
.babelrc don't work too:
#!/bin/bash
cat > index.js <<< 'export function* yo() { yield 1 }'
cat > package.json <<< '{"name":"a","devDependencies":{"microbundle":"0.12.3"}}'
cat > .babelrc <<'EOF'
{
"presets": [
[
"@babel/preset-env",
{
"exclude": ["transform-regenerator"]
}
]
]
}
EOF
yarn
yarn microbundle --no-compress
cat dist/a.js
Current workaround: patch microbundle. Below example shows how to patch microbundle without hassle using Yarn 2.
diff --git a/dist/cli.js b/dist/cli.js
index 5672733813ad0999e4f12d05d751951bc9a472a5..dd92b95369baa5fb67cfb019544dbbce14a450a1 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -237,9 +237,6 @@ var customBabel = (() => {
}, {
name: '@babel/plugin-proposal-class-properties',
loose: true
- }, !customOptions.modern && {
- name: '@babel/plugin-transform-regenerator',
- async: false
}, {
name: 'babel-plugin-macros'
}].filter(Boolean));
diff --git a/dist/microbundle.js b/dist/microbundle.js
index 91fd66a0e8da2f8e961c0f6fd43f00a926f0fc45..7b6bc7cb53688b5660156b1cd8b5ba65020b3bdf 100644
--- a/dist/microbundle.js
+++ b/dist/microbundle.js
@@ -236,9 +236,6 @@ var customBabel = (() => {
}, {
name: '@babel/plugin-proposal-class-properties',
loose: true
- }, !customOptions.modern && {
- name: '@babel/plugin-transform-regenerator',
- async: false
}, {
name: 'babel-plugin-macros'
}].filter(Boolean));
{
"devDependencies": {
"microbundle": "patch:[email protected]#./microbundle.patch"
}
}
Just to clarify: this only happens when running microbundle --target node, right? It wasn't included in your examples, but it seems to be the root cause here.
We don't use browserslist for the Node target and were incorrectly overriding the babel configuration in that case. I'm definitely open to allowing browserslist for Node, but I think we'd need to to it under a key ({"browserslist":{"node":"last 2 supported versions"}}) or using "engines.node".
Actually it didn’t worked for the browser target too. I ~~will change~~ have changed the example to clarify the issue.
@simnalamburt the two changes in #707 should still fix this, including for the browser target. The issue was that we had regenerator manually turned on because it isn't handled by the async-to-promises.
Fix #707 appears to be a PR with no change when it is not a nodeTarget. I'm not sure if #707 will fix this issue. I'll try it out when a new build of Microbundle comes out.
@developit Hi, was the proposed fix for this, #707 , ever released? I'm running into the same issue (specifically, my .babelrc file being ignored when targeting node) and I can't find it in any releases, though I may have overlooked it. Thanks for supporting this project, loving it so far!
The fix should be shipped - the only issue was that we forcibly transpile async to promises for Node.
I've updated the title to clarify issue more clearly!