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

Viewed 2350
 "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', () => {
    
    })```

I am getting this error

ā— Test suite failed to run. I tried configuring jest and babelrc but nothing worked for me. It works fine for pure react components but throws error, when I start testing components using redux store.

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)
2 Answers

yarn add react-redux or npm install react-redux

Your package.json doesn't have React in it. It's pretty hard for your project to use a package you haven't installed.

Just do npm install --save react, and you should be fine.

npm install --save react

Related