jmargolisvt jmargolisvt - 2 months ago 36
Javascript Question

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

I'm trying to get Jest to run a snapshot test of my React app. The versions from my package.json:

"react": "15.6.1",
"react-dom": "15.6.1",
"react-test-renderer": "15.6.1",


I can't get past this error:

● Test suite failed to run


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

at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (node_modules/react-test-renderer/lib/ReactDebugTool.js:16:30)


I have tried removing and reinstalling my node_modules dir and I've verified that the path to my component is correct but still get this same error.

My test looks like this:

import React from 'react';
import renderer from 'react-test-renderer';
import { Section } from '../../app/views/containers/section';

it('renders correctly', () => {
const section = renderer.create(
<Section key="1" section="finance"/>
).toJSON();
expect(section).toMatchSnapshot();
});


What am I doing wrong?

Answer Source

Ran into the similar problem last week, we have a React-Native project that has recently upgraded to:

"react-native": "0.45.1"
"react": "16.0.0-alpha.12"
"jest": "20.0.4"
"react-test-renderer": "15.5.4"

and then we try to run our Jest tests and we saw the same issue as you mentioned above. Then we realized there is a cutting edge version of the react-test-renderer and we tried that one out:

"react-test-renderer": "^16.0.0-alpha.12",

And now the issue is no longer there.