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

async/await is always transpiled into regenerator even with browserconfig or babelrc #705

Open
simnalamburt opened this issue Aug 19, 2020 · 9 comments
Labels
bug 🐛 has-fix A fix is available, but may not yet be released.

Comments

@simnalamburt
Copy link

simnalamburt commented Aug 19, 2020

Click to see workaround

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
@simnalamburt simnalamburt changed the title "browserslist" key of package.json is ignored "browserslist" key of package.json or ".babelrc" configs are ignored Aug 19, 2020
@simnalamburt
Copy link
Author

simnalamburt commented Aug 19, 2020

.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

@simnalamburt
Copy link
Author

simnalamburt commented Aug 19, 2020

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"
  }
}

simnalamburt added a commit to simnalamburt/xsalsa20-csprng that referenced this issue Aug 19, 2020
@developit
Copy link
Owner

developit commented Aug 19, 2020

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

@simnalamburt
Copy link
Author

simnalamburt commented Aug 20, 2020

Actually it didn’t worked for the browser target too. I will change have changed the example to clarify the issue.

@developit
Copy link
Owner

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

@simnalamburt
Copy link
Author

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 developit added bug 🐛 has-fix A fix is available, but may not yet be released. labels Dec 18, 2020
@Dmurl5
Copy link

Dmurl5 commented Jan 22, 2021

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

@developit
Copy link
Owner

The fix should be shipped - the only issue was that we forcibly transpile async to promises for Node.

@simnalamburt simnalamburt changed the title "browserslist" key of package.json or ".babelrc" configs are ignored async/await is always transpiled into regenerator even with browserconfig or babelrc Jan 24, 2021
@simnalamburt
Copy link
Author

I've updated the title to clarify issue more clearly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 has-fix A fix is available, but may not yet be released.
Projects
None yet
Development

No branches or pull requests

3 participants