Create-react-app: Classes & Generators: Can't combine?

Created on 21 Apr 2017  ·  7Comments  ·  Source: facebook/create-react-app

If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.

Can you reproduce the problem with latest npm?

Yes.

Description

When a script with both a js class and a generator are defined, compilation breaks.

Expected behavior

Compilation of script.

Actual behavior

Browser console logs error message "...Uncaught ReferenceError: _regeneratorRuntime is not defined"

Environment

npm ls react-scripts:
[email protected] /Users/angelbeltran/dev/test/my-app
└── [email protected]

node -v:
v7.0.0

npm -v:
4.5.0

  1. Operating system: MacOS Sierra, Version 10.12.4
  2. Browser and version: Google Chrome, 57.0.2987.133 (64-bit)

Reproducible Demo

https://github.com/angelbeltran/my-test-app

I added a simple class and generator to src/index.js.
Clone and enter the project, and run

npm start

When the browser opens, you'll get the error message I got.

bug underlying tools

All 7 comments

Interesting...

When a class is in the same file, the following is produced:

var _marked = [someGenerator].map(_regeneratorRuntime.mark);

Without a class, it is transformed correctly:

var _marked = [someGenerator].map(_regenerator2.default.mark);

Both still contain:


    var _regenerator = __webpack_require__(/*! ./~/babel-preset-react-app/~/babel-runtime/regenerator */ 89);

    var _regenerator2 = _interopRequireDefault(_regenerator);

The stray _regeneratorRuntime is the only token with that name in the entire bundle...

Seems like transform-runtime is misbehaving.

I wonder if we can reproduce this with an even more minimal project strictly using the babel chain ...

Looks very related, I see the same stray _regeneratorRuntime. 😄
Thanks for digging into that, @angelbeltran!

It would be great to check if it still happens on master.

This does not reproduce in master. I’m assuming it was fixed by disabling CommonJS transform.

I could reproduce using [email protected] with the same sample code provided by @angelbeltran. However I could not reproduce on latest master commit (5ecda24f76a0d64aba98f3f5059e25e1a9695ce6) using npm start.

Edit: Sorry didn't see your post @gaearon

Thanks, guys!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dualcnhq picture dualcnhq  ·  3Comments

AlexeyRyashencev picture AlexeyRyashencev  ·  3Comments

fson picture fson  ·  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  ·  3Comments

jnachtigall picture jnachtigall  ·  3Comments