H. Manner
H. Manner

Reputation: 285

ReactJS Test - fsevents is not a function

I am trying to write test cases for my program and I heard good things about testing-library/react and jest-junit. I used npm to install both packages into my devDependencies and change my script for test: "test": 'react-scripts test" When I run npm test, I get and error saying

TypeError: fsevents is not a function

So I tried to npm i fsevents but it did not help. I tried looking online but the errors there were either fsevents is not a constructor or change to yarn.

What is causing this issue? I am using npm v6.4.1 and react-script v3.1.1

Edit: Also using a Mac if that matters

Edi2: I ran the test again and did not get this error anymore without changing anything.

Upvotes: 16

Views: 13018

Answers (5)

the_haystacker
the_haystacker

Reputation: 1625

what you have to do is very simple. Run the following

rm -rf node_modules/ package-lock.json  

and then

npm i

This worked for me.

Upvotes: -2

Aditya Hajare
Aditya Hajare

Reputation: 1391

Had similar issue on OSX. If you have Homebrew, just run following command in terminal and try again:

brew install watchman 

If it doesn't help, try running following commands in terminal:

sudo rm -rf (xcode-select -print-path)
xcode-select --install

Upvotes: 46

g-merrill
g-merrill

Reputation: 131

Any time I did create-react-app, I got this exact error when I immediately ran 'npm test'. This worked for me if I already was committed to the React project:

npm install [email protected]

After some digging, I found out that I needed to manually install this package because CRA pumped out several

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] ...

messages during the initial install. And yet, I needed this package to run 'npm test'.

However, my bigger issue was that CRA was skipping this dependency install because it wasn't detecting xcode on my system. I was getting these messages:

gyp: No Xcode or CLT version detected!

The solution is to run the command

xcode-select --install

Now, any future create-react-app's should operate smoothly without needing any additional dependency installs! Additional Xcode troubleshooting here.

Upvotes: 13

Ed Gonzalez
Ed Gonzalez

Reputation: 1882

I had the same issue after a fresh install of node and create-react-app. After some searching I found this article [1] about a known issue with running npm test.

After installing watchman, tests are running.

[1] https://github.com/bbc/simorgh/wiki/Known-setup-issue-when-running-%60npm-test%60

Upvotes: 9

Jose Barranco
Jose Barranco

Reputation: 122

fsevents is installed by default with npm on Mac OS and Windows operating systems. The error "is not a constructor" might mean you tried to initialize fsevents in your code. Most likely with the new keyword. Please review your code for this, if not let me know.

Upvotes: -2

Related Questions