Skip to content

react-scripts test is watching files in node_modules #2393

Closed
@thisconnect

Description

@thisconnect

Can you reproduce the problem with latest npm?

yes

Can you still reproduce it?

yes, also did npm cache clean just to be sure

Description

This is a followup of "npm test hangs for newly generated app (#960)". After reading the comment of @hmeerlo that "Jest is trying to watch too many files at once (jestjs/jest#1767 (comment))" I suspect that files in node_modules are unnecessarily being watched.

Expected behavior

npm t should run without error.

Actual behavior

react-scripts test --env=jsdom

2017-05-28 09:18 node[1154] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-05-28 09:18 node[1154] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1018:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1420:11)
npm ERR! Test failed.  See above for more details.

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected): [email protected]
  2. node -v: v6.10.3
  3. npm -v: 4.6.1

Then, specify:

  1. Operating system: macOS Sierra 10.12.5
  2. Browser and version: -
  3. watchman never installed

Reproducible Demo

https://github.com/thisconnect/cra-desktop

Reproduce the error

This is an instantiated create-react-app (un-ejected) with electron added as described in PR #1718

git clone https://github.com/thisconnect/cra-desktop
cd cra-desktop
npm install
npm test

Without error (when removing 2 large dependencies)

Assuming react-scripts test is indeed watching files in node_modules, remove electron and electron-packager from devDependencies in package.json, then rm -rf node_modules && npm i && npm t, test mode runs fine. This does not yet prove that files in node_modules are being watched.

Strong indication that node_modules is being watched:

  • run any CRA instance without error
  • the Terminal should display something like "No tests found related to files changed since last commit" and the "Watch Usage"
  • open a random .js file in node_modules
  • for example node_modules/mime/mime.js
  • watch the Terminal (screenshot 1)
  • add a comment on any line i.e. // test
  • save the file
  • check if the terminal changed (screenshot 2)

Terminal before changing a random file in node_modules (screenshot 1)
screen shot 2017-05-28 at 9 56 55 am

Terminal after chaning a random file in node_modules (screenshot 2)
screen shot 2017-05-28 at 10 04 40 am

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions