Search code examples
reactjsreduxreact-redux

why do i get the Error Module not found: Can't resolve 'redux'


I'm new to redux I have created a demo wherein I have installed react redux and redux.

Folder Structure:

  src
    js
      store
        index.js
      action
        index.js
      reducers
        index.js
      index.js  ///////**2**
  index.js ///////////  **1**
  App.js .... etc

In 1 index.js I have the following code:

import index from "./js/index";

In 2 index.js I have the following code:

   import store from "../js/store/index";
   import { addArticle } from "../js/actions/index";

   window.store=store;
   window.addArticle=addArticle;

packages are all updated.
When I do npm start I get the following error:

./src/js/store/index.js
Module not found: Can't resolve 'redux' in 'E:\reacr-redux\src\js\store'

js/store/index.js

import { createStore } from "redux";
import rootReducer from "../reducers/index";

const store=createStore(rootReducer);

export default store;

reducers/index.js

import { ADD_ARTICLE } from "../constants/action-types";
 const initialState={
articles:[]
 };
  const rootReducer= ( state = initialState ,  action ) => {
    switch(action.type){
    case ADD_ARTICLE:
    state.articles.push(action.payload);
    return state;
    default :
    return state;
    }
   };
    export default rootReducer;

package.json

{
"name": "reacr-redux",
"version": "0.1.0",
 "private": true,
 "dependencies": {
"font-awesome": "^4.7.0",
"mdbootstrap": "^4.5.15",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-redux": "^5.1.1",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1"
 },
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",

 },
 "eslintConfig": {
   "extends": "react-app"
  },
 "browserslist": [
  ">0.2%",
  "not dead",
  "not ie <= 11",
  "not op_mini all"
  ],
 "devDependencies": {
   "redux": "^4.0.1"
   }
  }

Can anyone let me know what's happening?
I'm new to it where am I going wrong?


Solution

  • Do not use save-dev for Redux. Remove it from devDependencies:

    npm uninstall redux --save-dev
    

    and install it again with:

    npm i redux --save