Skip to content

jest error in Node version over 11.11 #6591

@micalgenus

Description

@micalgenus

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 jestjs/jest@800f2f8 (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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions