为什么找不到错误模块:无法解析"redux"



我是redux的新手,我创建了一个演示,其中我安装了react redux和redux

文件夹结构

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

1index.js中,我有以下代码

import index from "./js/index";

2index.js中,我有以下代码

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

程序包已全部更新当我npm启动时,我得到以下错误;

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

js/store/index.js

import { createStore } from "redux";
import rootReducer from "../reducers/index";
const store=createStore(rootReducer);
export default store;

减速器/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"
}
}

有人能告诉我发生了什么吗?我是新手,哪里错了

请勿将save-dev用于Redux。将其从devDependencies:中删除

npm uninstall redux --save-dev

并使用重新安装

npm i redux --save

只需安装react工具包就可以解决问题。

# NPM
npm install @reduxjs/toolkit
# Yarn
yarn add @reduxjs/toolkit

运行npm install@reduxjs/toolkit后,尝试重新启动服务器。

使用它来安装React Reduxnpm install@reduxjs/toolkit

相关内容

  • 没有找到相关文章

最新更新