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 & regeneratorRuntime & (babel?) #3012

Closed
DrYSG opened this issue May 10, 2019 · 6 comments
Closed

async & regeneratorRuntime & (babel?) #3012

DrYSG opened this issue May 10, 2019 · 6 comments

Comments

@DrYSG
Copy link

DrYSG commented May 10, 2019

Is this an issue with babel, or with parcel? I cannot figure that out.

Chrome V74 is complaining when I include this async method into my JSX react file:

 const fetcher = (async () => {
    const url = 'https://epicorapp2/ERP10.1Test/api/v1/Erp.BO.JobEntrySvc/GetNextJobNum'
    const rawResponse = await fetch(url, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Authorization': 'Basic xxxxx=',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({})
    });
    const nJob = await rawResponse.json()
    console.log(nJob)
    return nJob
  })();

Here is the trace:

react-lifecycles-compat.es.js:134 Uncaught ReferenceError: regeneratorRuntime is not defined
    at Object.parcelRequire.App.jsx.react (react-dom.development.js:21278)
    at newRequire (StyleRule.js:13)
    at localRequire (Controls.jsx:29)
    at Object.parcelRequire.Main.jsx.react (react-dom.development.js:21278)
    at newRequire (StyleRule.js:13)
    at redux.js:65
    at Popover.js:105

Here is my babelrc

{
    "presets": [
        [
            "env",
            {
                "targets": {
                    "browsers": [
                        "last 1 versions"
                    ]
                }
            },
            "@babel/preset-react"
        ]
    ]
}
@DrYSG DrYSG changed the title async & regeneratorRuntime & (babel) async & regeneratorRuntime & (babel?) May 10, 2019
@DrYSG DrYSG closed this as completed May 13, 2019
@DrYSG DrYSG reopened this May 17, 2019
@DrYSG
Copy link
Author

DrYSG commented May 17, 2019

The babel developers have decided this is a parcel bug. I.e. they can use babel cli, the source files I provided them, and my .babelrc and create a valid bundle.

See issue: babel/babel#9971

and they cite an open issue with parcel:

#1762

@DrYSG
Copy link
Author

DrYSG commented May 17, 2019

BTW, the solution I am looking for should not load the regenerateRuntime. There is no reason to use it when one is targeting Google Chrome 74+ and MS Edge Chromium 76+

@niwinz
Copy link

niwinz commented May 19, 2019

It is not only related to regenerator, I have configured babelrc to use "last 1 Chrome version" that already supports class syntax, but when parcel generates the bundle it transpiles it to the old code using functions:

var Foo = function Foo(name) {
  _classCallCheck(this, Foo);

  this.name = name;
};
// [...]

when it should leave it untouched as it defined using ES6 classes:

class Foo {
  constructor(name) {
    this.name = name;
  }
}

I have tried to build the same code and the same .babelrc using babel-cli and the outout is correct with babel-cli. Seems like parcel does not respects the .babelrc file for some reasons. This is my .babelrc file:

{
  "presets": [
    ["@babel/preset-env", {"targets": {"browsers": "last 1 Chrome versions"}}],
    ["@babel/preset-react"]
  ],
  "plugins": ["@babel/plugin-proposal-class-properties"]
}

@mischnic
Copy link
Member

@niwinz You should use .browserslistrc or the "browserslist" key in package.json to tell Parcel your target environment.
This works:

{
  "browserslist": ["last 1 Chrome versions"],
  "dependencies": {
    "@babel/core": "^7.4.5",
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "@babel/preset-env": "^7.4.5",
    "@babel/preset-react": "^7.0.0",
    "parcel-bundler": "^1.12.3"
  }
}

As for the regeneratorRuntime error, please follow #1762.

@DrYSG
Copy link
Author

DrYSG commented Jun 21, 2019

@niwinz Perfect. Thanks this is great. Now we can close this.

@niwinz
Copy link

niwinz commented Jun 21, 2019

I think parcel should respect the .babelrc config, ignoring it is counterintuitive...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants