【问题标题】:Redux: Module not found: Can't resolve 'redux'Redux:找不到模块:无法解析“redux”
【发布时间】: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


【解决方案1】:

找到解决办法:从package.json删除redux,然后重新安装。看来我在redux之前安装react-redux不小心搞砸了package.json

【讨论】:

    猜你喜欢
    • 2021-11-03
    • 2021-11-23
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2020-11-23
    • 2019-11-19
    • 2017-06-06
    相关资源
    最近更新 更多