question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-scripts test is watching files in node_modules

See original GitHub issue

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 (https://github.com/facebook/jest/issues/1767#issuecomment-250719565)” 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): react-scripts@1.0.7
  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 https://github.com/facebookincubator/create-react-app/pull/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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

24reactions
diptendulkarcommented, Jun 30, 2017

Reinstalling watchman fixed this error for me.

brew uninstall watchman brew install watchman

2reactions
andrew-oxenburghcommented, Aug 22, 2017

I did a sudo port install watchman, and problem went away.

Apparently you need watchman installed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable file watching in a react app - node.js
My question is now whether it is possible to launch a react app with react-scripts in a production-like environment where I don't necessarily ......
Read more >
Running Tests
When you run npm test , Jest will launch in watch mode *. Every time you save a file, it will re-run the...
Read more >
Everything you need to know about react-scripts
React uses Node.js on development to open the app on ... The test script enables you to launch the test runner in interactive...
Read more >
ts-node
ts , runtime vs tests) and parsing every file for types slows startup time. Instead, ts-node starts with the script file (e.g. ts-node...
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... This option tells Jest that all imported modules in your tests should be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found