简体   繁体   English

玩笑失败 React 16 升级后无法从“ReactShallowRenderer.js”中找到模块“react/lib/React”

[英]Jest fails Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js' after React 16 upgrade

Just upgraded to react v16.0.0 from v15.6.2 (via a rebase)刚刚从 v15.6.2 升级到反应 v16.0.0(通过 rebase)

Problem问题

Running my jests tests gives the following error运行我的笑话测试会出现以下错误

  ● Test suite failed to run

    Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
      at Object.<anonymous> (node_modules/react-test-renderer/lib/shallow/ReactShallowRenderer.js:16:13)

How I upgraded我是如何升级的

Step 1: yarn.lock第 1 步:yarn.lock

During the rebase, onto a branch with React v16 - I let yarn 1.1.0 take care of merge conflicts on my yarn.lock file在 rebase 期间,使用 React v16 到一个分支上 - 我让yarn 1.1.0 处理我的 yarn.lock 文件上的合并冲突

Step 2: Add adapter第 2 步:添加适配器

I added the new adapter setupTestFramework.js我添加了新的适配器setupTestFramework.js

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });

Step 3: upgrade packages第三步:升级包

And upgraded the following packages:并升级了以下软件包:

react "16.0.0",
enzyme "3.1.0",
jest "21.2.1",
babel-jest "21.2.0",

Can anyone see anything I missed?谁能看到我错过的任何东西?

当与 React 16 一起使用时,Enzyme 需要v16.xx react-test-renderer v16.xx

Worked for me by following below comand按照以下命令为我工作

npm uninstall react-dom  

and then然后

  npm install react-dom --save-dev 

暂无
暂无

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

相关问题 Jest失败并出现错误:无法找到模块&#39;react / lib / ReactComponentTreeHook&#39; - Jest fails with error: Cannot find module 'react/lib/ReactComponentTreeHook' 无法从&#39;ReactTestUtils.js&#39;找到模块&#39;react / lib / React&#39; - Cannot find module 'react/lib/React' from 'ReactTestUtils.js' 用酶和玩笑测试 React 给出错误无法从“index.js”中找到模块“@babel/polyfill/lib/noConflict” - Testing React with enzyme and jest giving error Cannot find module '@babel/polyfill/lib/noConflict' from 'index.js' 无法从“ReactDebugTool.js”中找到模块“react/lib/ReactComponentTreeHook” - Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js' REACT JEST错误无法从&#39;jest-expect.js&#39;中找到模块&#39;jest-matchers&#39; - REACT JEST error Cannot find module 'jest-matchers' from 'jest-expect.js' 如何解决 React 项目中的酶/Jest 错误“无法从 &#39;react-router.js&#39; 中找到模块 &#39;react&#39;” - How to solve an Enzyme/Jest error "Cannot find module 'react' from 'react-router.js'" in a React project 设置Jest和Enzyme以测试React 15无法找到模块react / lib / ReactTestUtils - Setting up Jest and Enzyme to test React 15 cannot find module react/lib/ReactTestUtils 开玩笑测试:无法从'Link.react.js'中找到模块'../Link.react' - Jest test: Cannot find module '../Link.react' from 'Link.react.js' 浏览器控制台错误:无法从“ react / lib / ReactAddonsDOMDependencies.js”中找到模块“ react-dom / lib / ReactPerf” - Browser Console error: Cannot find module 'react-dom/lib/ReactPerf' from 'react/lib/ReactAddonsDOMDependencies.js' 开玩笑找不到模块@env React Native - Jest cannot find module @env React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM