Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve 'redux' in node_modules

When I used typescript to create my react project, I introduced Redux error reporting, which indicated that I could not find it, but I had to install all the dependencies.

Here's my package.json

{
  "name": "react-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "^24.0.11",
    "@types/node": "^11.11.3",
    "@types/react": "^16.8.8",
    "@types/react-dom": "^16.8.2",
    "@types/react-redux": "^7.0.3",
    "@types/react-router-dom": "^4.3.1",
    "axios": "^0.18.0",
    "react": "^16.8.4",
    "react-dom": "^16.8.4",
    "react-redux": "^6.0.1",
    "react-router-dom": "^4.4.0",
    "react-scripts": "2.1.8",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "typescript": "^3.3.3333"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "babel-plugin-import": "^1.11.0",
    "customize-cra": "^0.2.12",
    "node-sass": "^4.11.0",
    "react-app-rewired": "^2.1.1"
  }
}

Here's my store

import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'

import reducer from './reducer'


const store = createStore(reducer, composeWithDevTools(
   applyMiddleware(thunk)
))

Unfortunately, the app doesn't compile and it complains with:

./node_modules/[email protected]@react-redux/es/connect/mapDispatchToProps.js
Module not found: Can't resolve 'redux' in '~/node_modules/[email protected]@react-redux/es/connect'

What should I do is right. Please help me, thanks.

like image 585
ming xiao Avatar asked Mar 16 '19 17:03

ming xiao


People also ask

How to solve the error “module not found”?

To solve the error "Module not found: Error: Can't resolve 'redux'", make sure to install the redux package by opening your terminal in your project's root directory and running the command npm install redux react-redux and restart your development server.

Where is the Redux module installed?

The redux module should NOT be globally installed or be in your project's devDependencies, it should be in the dependencies object in your package.json file. You can try to manually add the lines and re-run npm install.

How to solve the error 'module not found' in ReactJS?

To solve the error "Module not found: Error: Can't resolve 'react/jsx-runtime'", make sure to update the react package by opening your terminal in your project's root directory and running the command npm install react@latest react-dom@latest and restart your dev server.

Do I need to install React-Redux If I have Redux?

You need to install react-redux but also a redux library, both are kind of dependent on each other. Don't forget to import it. Show activity on this post. Show activity on this post. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid …


4 Answers

Try to install both redux and react-redux at same time:

npm install --save redux react-redux

like image 129
James Delaney Avatar answered Oct 19 '22 17:10

James Delaney


This worked for me

npm install --save redux react-redux

like image 33
amit sharma Avatar answered Oct 19 '22 18:10

amit sharma


For people that might come across this in the future, I came across the same issue.

I was calling connect(mapStateToProps, null)(Component). All I had to do was actually pass in a proper mapDispatchToProps argument and it solved the problem.

It had nothing to do with redux not being properly installed.

like image 30
Shadow Boost Avatar answered Oct 19 '22 19:10

Shadow Boost


--save means that dependency install as local dependency, that means related for that particular project.

npm install redux -g in here redux install as global dependency

like image 4
Supun Sandaruwan Avatar answered Oct 19 '22 17:10

Supun Sandaruwan