Jest will not work after re-installing Node modules

I’ve created a project with the Expo CLI (expo init) and when I initially create it I can run Jest tests with npm test. However, if I delete my node_modules folder and then re-install all my modules with npm i I can no longer run Jest tests.

First I get this error:

Error: Cannot find module ‘…/node_modules/jest/bin/jest.js’

So I changed the “test” script to jest --watchAll in package.json. After doing this Jest runs but I get this error:

…/node_modules/react-native/jest/mockComponent.js: Unexpected token (20:23)

This line in question has this piece of code:

static displayName = ‘Component’;

I’ve compared the node_modules folder for the initial Expo CLI creation with the reinstalled version using DiffMerge and mockComponent.js is exactly the same in both. In fact, the only difference I see in DiffMerge is that the re-installed modules’ package.json has more metadata (_requiredBy, etc).

Is there an Expo-specific way to re-install Node modules? Am I doing something wrong? Is this a bug?

I have this issue on both Windows 10 and macOS 10.13.
Expo CLI version: 2.4.0
Expo version: 31.0.2
Jest Expo version: 31.0.0
React Native version 31.0.0

I’ve updated to Expo CLI v2.6.0 and am still getting this error when running npm test after re-installing Node modules. However, switching to Yarn has resolved the issue.

Thanks for sharing that Yarn works, @noobsarepeople2. Random side note: Love your username.:ok_hand: My AIM screen name from way back was bumsrppl2.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.