我是redux的新手,我创建了一个演示,其中安装了react redux和redux
文件夹结构
src
js
store
index.js
action
index.js
reducers
index.js
index.js ///////**2**
index.js /////////// **1**
App.js .... etc
在 1 index.js中,我具有以下代码
import index from "./js/index";
在 2 index.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-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"
}
}
任何人都能知道我是怎么回事我在哪里错了
答案 0 :(得分:3)
请勿将save-dev用于redux。从devDependencies中将其删除npm卸载redux --save-dev并使用以下命令再次安装:npm i redux --save
答案 1 :(得分:1)
只需安装 react toolkit 即可解决问题。
# NPM
npm install @reduxjs/toolkit
# Yarn
yarn add @reduxjs/toolkit
答案 2 :(得分:1)
在运行 npm install @reduxjs/toolkit 后尝试重新启动服务器。