Jest fails with error: Cannot find module 'rea

2020-05-25 18:21发布

I have installed Jest v17.0.3 in my react project.

When I run jest locally it works fine, but on the build server it fails with:

Error: Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js'

Both machines are running node version 6.9.1 and npm version 4.0.2.

4条回答
别忘想泡老子
2楼-- · 2020-05-25 18:24

I had the same issue and i removed the node_modules and ran npm install and it fixed the problem.

查看更多
走好不送
3楼-- · 2020-05-25 18:32

In the latest versions of react we often see this error as we have loaded 2 versions of react:

To make sure you have just 1 version, run the following in your terminal:

  1. npm ls react-dom enter image description here

  2. npm ls react enter image description here

Both the react and react-dom versions need to be same. If any one of these returns more than 1 version then that's not supported. You have to then correct it in your corresponding package.json

查看更多
时光不老,我们不散
4楼-- · 2020-05-25 18:33

use same version of react and react-dom. My problem fixed after using this command

npm install --save react@15.4.0 react-dom@15.4.0

this problem specially occurs on react 15.4.0 above.

查看更多
太酷不给撩
5楼-- · 2020-05-25 18:38

Can you check which version of React you are using? Is it the same on both servers? I would try removing node_modules and reinstalling the dependencies. The reason I am suggesting this is that in React v15.4.0 you cannot import private apis and it seems that ReactDebugTools.js is trying to import from react/lib/....

From the blogpost about React v15.4.0 (Link):

However, there is a possibility that you imported private APIs from react/lib/*, or that a package you rely on might use them. We would like to remind you that this was never supported, and that your apps should not rely on internal APIs. The React internals will keep changing as we work to make React better.

Hope this helps!

查看更多
登录 后发表回答