【发布时间】:2021-03-07 16:09:44
【问题描述】:
我已经安装了 redux 和 react-redux 使用
npm install --save redux react-redux
我正在尝试使用来自 App.js 的 Redux 箭头函数,如下所示:
import './App.css';
import MenuItems from './components/Navbar/MenuItems';
import ReactDOM from 'react-dom';
import React, { useState } from 'react';
import { createStore } from 'redux';
import {AddItemToCart, DeleteItemFromCart, Counter} from './cart.js';
let store = createStore(Counter);
store.subscribe(() => console.log(store.getState()));
<button onClick="store.dispatch(AddItemToCart())">Add to cart</button>
这是我的cart.js:
import React from 'react';
import ReactDOM from 'react-dom';
export const AddItemToCart = () => {
return {
name: 'ADDITEMTOCART'
}
}
export const DeleteItemFromCart = () => {
return {
name: 'DELETEITEMFROMCART'
}
}
export const Counter = (state = 0, action) => {
switch (action.type) {
case 'ADDITEMTOCART':
return state + 1;
case 'DELETEITEMFROMCART':
return state - 1;
}
}
但这不会编译,我收到错误消息:
Module not found: Can't resolve 'redux' in 'C:\Users\Admin\Documents\projects\Web_projects\myapp\myapp\src'
非常感谢任何建议。
编辑:我跑了
npm install --save redux
现在错误信息变为:
./src/App.js
Module not found: Recursion in resolving
【问题讨论】:
-
你知道具体是哪个文件给你这个错误吗?你在 webpack 中做过什么时髦的事情吗?
-
只涉及两个文件:App.js 和 cart.js。使用“npm start”启动开发服务器后,首页出现此错误。
-
这能回答你的问题吗? Module not found: 'redux'
-
@0stone0 好吧,我专门重新安装了redux,现在错误消息发生了变化:找不到模块:解析中的递归
标签: reactjs redux react-redux