简体   繁体   English

无法从“ReactDebugTool.js”中找到模块“react/lib/ReactComponentTreeHook”

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

I'm trying to get Jest to run a snapshot test of my React app.我试图让 Jest 运行我的 React 应用程序的快照测试。 The versions from my package.json:我的 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.我已经尝试删除并重新安装我的 node_modules 目录,并且我已经验证了我的组件的路径是正确的,但仍然得到同样的错误。

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?我究竟做错了什么?

Ran into the similar problem last week, we have a React-Native project that has recently upgraded to: 上周遇到类似的问题,我们有一个最近升级到的React-Native项目:

"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. 然后我们尝试运行我们的Jest测试,我们看到了与上面提到的相同的问题。 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" , "react-test-renderer": "^16.0.0-alpha.12"

And now the issue is no longer there. 现在问题不再存在了。

On 0.47.0 在0.47.0

Still had errors with the accepted answer had to do the following: 仍然有错误,接受的答案必须做到以下几点:

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

enzyme will work with the above changes but any sort of simulation will not, disabled taps until they support. 酶将适用于上述变化,但任何类型的模拟都不会,禁用水龙头直到它们支持。

升级到React 16.0.0时,我确实注意到你确实需要将react-dom升级到16.0.0并且它完美无瑕!

在撰写本文时(2022 年),名为“storyshots”的包(旧包的链接以供参考)已被弃用并替换为“@storybook/addon-storyshots”,请参阅官方文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 迁移到React 16.0.0错误:找不到模块“ react / lib / ReactComponentTreeHook” - Migration to React 16.0.0 Error: Cannot find module “react/lib/ReactComponentTreeHook” 更新到React 16.2.0时找不到模块“ react / lib / ReactComponentTreeHook”错误 - cannot find module “react/lib/ReactComponentTreeHook” error when updating to React 16.2.0 无法从&#39;ReactTestUtils.js&#39;找到模块&#39;react / lib / React&#39; - Cannot find module 'react/lib/React' from 'ReactTestUtils.js' ReactJS:找不到模块:无法解析&#39;react / lib / ReactComponentTreeHook&#39; - ReactJS: Module not found: Can't resolve 'react/lib/ReactComponentTreeHook' 创建反应应用程序时出现此错误:找不到模块&#39;./lib/pack.js&#39; - When creating react app this error appears: Cannot find module './lib/pack.js' 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):错误:找不到模块“babel-preset-react” - Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-preset-react' 找不到&#39;react-native-implementation.js&#39;中的模块 - Cannot find module from 'react-native-implementation.js' node.js找不到模块&#39;./lib/compat&#39; - node.js Cannot find module './lib/compat' NPM:找不到模块“../lib/utils/unsupported.js” - NPM: Cannot find module '../lib/utils/unsupported.js' 无法从“Provider.js”中找到模块“react” - Cannot find module 'react' from 'Provider.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM