create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

jest error in Node version over 11.11

Open micalgenus opened this issue 7 years ago • 38 comments

PS. I do not speak English well. Please understand.

Is this a bug report?

Yes

Did you try recovering your dependencies?

yes / Initialized project with npx create-react-app my-project

Which terms did you search for in User Guide?

jest, jest version

Environment

$ npx create-react-app --info npx: installed 63 in 8.392s

Environment Info:

System: OS: Linux 4.4 Ubuntu 18.04.2 LTS (Bionic Beaver) CPU: x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz Binaries: Node: 11.11.0 - ~/.nvm/versions/node/v11.11.0/bin/node Yarn: 1.13.0 - /usr/bin/yarn npm: 6.7.0 - ~/.nvm/versions/node/v11.11.0/bin/npm npmPackages: react: ^16.8.4 => 16.8.4 react-dom: ^16.8.4 => 16.8.4 react-scripts: 2.1.8 => 2.1.8 npmGlobalPackages: create-react-app: Not Found

Steps to Reproduce

  1. install node version 11.11. (only over 11.11. There is no problem with other versions.)
  2. npx create-react-app myproject && cd myproject
  3. yarn test # this step error

Expected Behavior

Currently, the LTS version of node.js is 10, but will change from 2019-04-01 to version 11. That's why I think we need to fix the problem.

This problem has been fixed as follows after facebook/jest@800f2f803d01c8ae194d71b251e4965dd70e5bf2 (v24.2.0-alpha.0).

newProcess[Symbol.toStringTag] = 'process';

modify to

 try {
    // This fails on Node 12, but it's already set to 'process'
    newProcess[Symbol.toStringTag] = 'process';
  } catch (e) {
    // Make sure it's actually set instead of potentially ignoring errors
    if (newProcess[Symbol.toStringTag] !== 'process') {
      e.message =
        'Unable to set toStringTag on process. Please open up an issue at https://github.com/facebook/jest\n\n' +
        e.message;

      throw e;
    }
  }

I used the 10.15.3 node and tried the 24.3.0 Jest. As a result, it worked fine. But I have not tested it for other versions of the node.

Actual Behavior

$ CI=true yarn test
yarn run v1.13.0
$ react-scripts test
FAIL src/App.test.js
  ● Test suite failed to run

    TypeError: Cannot assign to read only property 'Symbol(Symbol.toStringTag)' of object '#<process>'

      at exports.default (node_modules/jest-util/build/create_process_object.js:15:34)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        3.291s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The same is true without "CI=true".

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

micalgenus avatar Mar 07 '19 16:03 micalgenus

same here.

LesterLyu avatar Mar 07 '19 18:03 LesterLyu

I'm getting the same error

jmarlow4 avatar Mar 07 '19 19:03 jmarlow4

Experiencing the same on node@latest, downgrading to node 10.6.0 makes everything fine and dandy.

viktorlarsson avatar Mar 08 '19 08:03 viktorlarsson

Me too the same error. Hey @viktorlarsson what if reactjs ?

huxaiphaer avatar Mar 08 '19 08:03 huxaiphaer

Got the same error on the latest node image

soer7022 avatar Mar 08 '19 09:03 soer7022

Same here

CaptainJojo avatar Mar 08 '19 09:03 CaptainJojo

There is no error with node v11.10.1, but it is with v11.11.0 Example v11.10.1:

npx create-react-app my-app
cd my-app
docker run -it --rm -v $(PWD):$(PWD) -w $(PWD) node:11.10.1-alpine yarn test

 PASS  src/App.test.js (13.661s)
  ✓ renders without crashing (48ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        20.784s

Example v11.11.0:

npx create-react-app my-app
cd my-app
docker run -it --rm -v $(PWD):$(PWD) -w $(PWD) node:11.11.0-alpine yarn test

 FAIL  src/App.test.js
  ● Test suite failed to run

    TypeError: Cannot assign to read only property 'Symbol(Symbol.toStringTag)' of object '#<process>'

      at exports.default (node_modules/jest-util/build/create_process_object.js:15:34)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        5.643s

someden avatar Mar 08 '19 10:03 someden

same here

DavidODonovan avatar Mar 08 '19 11:03 DavidODonovan

Same here

dbenchi avatar Mar 08 '19 11:03 dbenchi

Please fix this :(

Marjona6 avatar Mar 08 '19 11:03 Marjona6

If you need to get this to work with node 11.11 and you cannot downgrade...

It is already fixed with newer jest version. You can upgrade your own jest version besides create-react-app by installing jest-util@^23.4.0 Also you have to create a .env-File and to bypass the Preflight-Check. echo "SKIP_PREFLIGHT_CHECK=true" >> .env

The complete cmd that solves the issue for myself is: echo "SKIP_PREFLIGHT_CHECK=true" >> .env && npm i jest-util@^23.4.0 --save-dev

Until create-react-app has updated to newer jest-version, we can remove jest from our package.json and also reactivate this skipped preflight-check.

mricharz avatar Mar 08 '19 11:03 mricharz

if you use gitlab CI you can change image: node:latest into image: node:10.6.0

soer7022 avatar Mar 08 '19 12:03 soer7022

What worked for me was changing the version of Jest to 24.3.0. I also had to remove the lockfiles and reinstall before tests passed again on Travis. Hope this helps.

Marjona6 avatar Mar 08 '19 13:03 Marjona6

[email protected] works fine, you don't need to downgrade to 10.6. The one with problems is [email protected]

FezVrasta avatar Mar 08 '19 14:03 FezVrasta

What worked for me was changing the version of Jest to 24.3.0. I also had to remove the lockfiles and reinstall before tests passed again on Travis. Hope this helps.

As @Marjona6 stated it's fixed since version 24.3.0 so this issue should be closed.

meeroslav avatar Mar 08 '19 14:03 meeroslav

its not fixed in create-react-app since it doesn't bring jest 24 with it. It should be "awaiting" for this PR to be merged: https://github.com/facebook/create-react-app/pull/6278

goldo avatar Mar 08 '19 15:03 goldo

NOT fixed when using create-react-app.

DavidODonovan avatar Mar 08 '19 15:03 DavidODonovan

I set node_js to 11.10.0 and jest to 24.3.1 and it still fails for the same issue on travis.

rpearce63 avatar Mar 08 '19 16:03 rpearce63

Travis build still failing for create-react-app.

Things I have tried:

  • set node to version 10.6.0,
  • deleted package.lock.json,
  • deleted node_modules,
  • installed jest@^24.3.0
  • update .travis.yml to include: "echo "SKIP_PREFLIGHT_CHECK=true" >> .env"

All as per instructions in error log at travis-ci.

Nothing has worked for me.

DavidODonovan avatar Mar 09 '19 04:03 DavidODonovan

Thank you all. I solved this by using node 11.10.

@Marjona6 I think this is caused by setting the Symbol.toStringTag member to read-only on the process object as the node version goes up to 11.11.

However, this can change in this PR(nodejs/node#26488) to Writable. So I'm not sure yet.

@rpearce63, @DavidOD Both are using node:alpine in Dockerfile. This version is 11.11.

micalgenus avatar Mar 09 '19 05:03 micalgenus