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

Generator class throws an error in development build #4371

Closed
robertedjones opened this issue Apr 27, 2018 · 2 comments
Closed

Generator class throws an error in development build #4371

robertedjones opened this issue Apr 27, 2018 · 2 comments

Comments

@robertedjones
Copy link

Is this a bug report?

Yes

Did you try recovering your dependencies?

1.6.0

Which terms did you search for in User Guide?

Babel, Generator Functions

Environment

  1. node -v: 8.11.1
  2. npm -v: 5.6.0
  3. yarn --version (if you use Yarn): 1.6.0
  4. npm ls react-scripts (if you haven’t ejected): react-scripts@2.0.0-next.66cc7a90

Then, specify:

  1. Operating system: Windows 10
  2. Browser and version (if relevant): Chrome 65.0.3325.181, Firefox Quantum 59.0.2 (64-bit)

Steps to Reproduce

During a development build Babel does not correctly convert generator functions in a class. The exact issue I am experiencing is described in this issue facebook/regenerator#287 but that appears to have since been resolved. This issue only occurs in a development build and works correctly during a production build. It was working correctly in react-scripts 1.x. - react-scripts@2.0.0-next.66cc7a90 is the first 2.x build I have tried. This may be a Babel issue rather than a CRA issue.

  1. Create a generator class
export default class GeneratorClass {
  *getReply(msg) {
    yield msg;
  }
}
  1. Invoke the classs
const reply = new Reply();
var r = reply.getReply('Hello ');
console.log('gen', r.next());
  1. yarn start
  2. ReferenceError: _callee is not defined

Expected Behavior

Babel correctly transpiles generator functions in a class and no error is given

Actual Behavior

The error:

ReferenceError: _callee is not defined

Reproducible Demo

https://github.com/robertedjones/my-app

@SenyaMur
Copy link

Add to package.json
"react-app-rewired": "^1.5.2"
Update "react-scripts" to "2.0.0-next.3e165448"
Update babel dependencies in package.json

    "@babel/core": "^7.0.0-rc.1",
    "@babel/plugin-proposal-class-properties": "^7.0.0-rc.1",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0-rc.1",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0-rc.1",
    "@babel/plugin-transform-classes": "^7.0.0-rc.1",
    "@babel/plugin-transform-destructuring": "^7.0.0-rc.1",
    "@babel/plugin-transform-react-constant-elements": "^7.0.0-rc.1",
    "@babel/plugin-transform-react-display-name": "^7.0.0-rc.1",
    "@babel/plugin-transform-regenerator": "^7.0.0-rc.1",
    "@babel/plugin-transform-runtime": "^7.0.0-rc.1",
    "@babel/preset-env": "^7.0.0-rc.1",
    "@babel/preset-react": "^7.0.0-rc.1",
    "@babel/runtime": "^7.0.0-rc.1"

Add config-overrides.js for enable use .babelrc

module.exports = {
    webpack: function(config, env) {
      const oneOf =config.module.rules.find(i=> i.oneOf).oneOf
      oneOf[1].use[1].options.babelrc= true;  
      return config;
    }
  };

.babelrc

{
  "presets": [
    ["@babel/preset-env", {
      "targets": {
        "browsers": ["last 2 versions", "safari >= 7"]
      },
      "include": ["transform-arrow-functions", "es6.map"],
      "exclude": ["transform-regenerator", "es6.set"]
    }]
  ]
}

@Timer Timer added this to the 2.0.0 milestone Sep 17, 2018
@Timer Timer modified the milestones: 2.0.x, 2.0.0-final, 2.0.0 Sep 26, 2018
@Timer
Copy link
Contributor

Timer commented Sep 27, 2018

This should be fixed with #4630

@Timer Timer closed this as completed Sep 27, 2018
@lock lock bot locked and limited conversation to collaborators Jan 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants