Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 225
H. Manner Avatar asked Nov 07 '19 16:11

H. Manner


3 Answers

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
like image 72
Aditya Hajare Avatar answered Oct 05 '22 10:10

Aditya Hajare


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.

like image 30
g-merrill Avatar answered Oct 05 '22 10:10

g-merrill


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

like image 21
Ed Gonzalez Avatar answered Oct 05 '22 12:10

Ed Gonzalez