我是新的redux我已经创建了一个演示,其中我有安装Reactredux和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-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"
}
}
有谁能告诉我发生了什么事吗?我是新来的,我哪里错了
4条答案
按热度按时间pkln4tw61#
不要在Redux中使用
save-dev
。从devDependencies
中删除:并使用以下命令重新安装:
ctehm74n2#
只需安装react工具包就可以解决这个问题。
2j4z5cfb3#
运行 npm install @reduxjs/toolkit 后,尝试重启服务器。
ssm49v7z4#
使用此命令安装React Redux npm install @reduxjs/toolkit