无法从'Provider.js'中找到模块'react'

问题描述 投票:0回答:1
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/preset-env": "^7.8.4",
"@babel/preset-react": "^7.8.3",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"react": "^15.3.1",
"redux-mock-store": "^1.5.4"

}

 //Test.js
    import React from "react";
    import { render, unmountComponentAtNode } from "reactdom";
    import { shallow,mount } from "enzyme";`enter code here`
    import {Provider} from 'react-redux'
    import configureMockStore from 'redux-mock-store';
    import App from "../../App";

    let container = null;

    let mockStore = configureMockStore()
    beforeEach(() => {
    container = document.createElement("div");
    document.body.appendChild(container);
    });

    afterEach(() => {
    unmountComponentAtNode(container);
    container.remove();
    container = null;
    });

    it('It RENDERS WITHOUT CRASHING', () => {
    
    })```

我收到此错误

●测试套件无法运行。我尝试配置jest和babelrc,但没有任何效果。当我开始使用redux存储测试组件时,它对于纯React组件工作正常,但会引发错误。

Cannot find module 'react' from 'Provider.js'

However, Jest was able to find:
    'components/Provider.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (../../node_modules/react-redux/lib/components/Provider.js:10:38)
javascript reactjs react-redux redux-saga babel-jest
1个回答
0
投票
您的package.json中没有React。您的项目要使用尚未安装的软件包非常困难。

只需执行npm install --save react,就可以了。

npm install --save react

© www.soinside.com 2019 - 2024. All rights reserved.