create-react-app: jest error in Node version over 11.11

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® Core™ 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.)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 55
  • Comments: 38 (4 by maintainers)

Commits related to this issue

Most upvoted comments

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

Hey guys, lot of people are subscribed to this issue to be warned when a fix gets released. Please may you refrain from posting all your very own personal solutions that explain how did you downgrade your Docker images to use node <11.11 please?

node 11.12 fixed it

None of the solutions in this thread have helped me, so yes, please refrain from posting what personally worked for you until a solution exists that works for everybody, this is frustrating.

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

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.

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

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.

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

None of the solutions in this thread have helped me, so yes, please refrain from posting what personally worked for you until a solution exists that works for everybody, this is frustrating.

How are you supposed to know if it works for everyone or not?

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

node@11.10.0 works fine, you don’t need to downgrade to 10.6. The one with problems is node@11.11.0

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.

Closing as it sounds like this is resolved in Node 11.12

I was using node:10.15-alpine when I encountered this problem. I subsequently tried to

  • change Dockerfile to use version node:11.10-alpine
  • change Dockerfile to use node:11.9-alpine
  • regenerate package-lock.json and reinstall node_modules

I cannot force the newer Jest version because I cannot use a separate .env file. My .env files are generated per environment. I don’t really want to skip the preflight checks. I’m thinking I’ll try different node versions until something works. I’m hoping this gets a create-react-app fix soon.

Travis-Ci build success! Confirm: changing Dockerfile to use node:11.10-alpine has fixed my problems at travis-ci. I did the same thing a couple of days ago and it didn’t work, but now it does. No need to change .travis.yml, or any other settings. Thanks guys.

I managed to solve this issue by migrating from Travis to Circle CI, I think there some additional configurations needed in Travis CI. @DavidOD

NOT fixed when using create-react-app.