0

I have installed redux and react-redux using

npm install --save redux react-redux

I'm trying to use Redux arrow functions from App.js like this:

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>

Here is my 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;
    }
}

But that won't compile, I get error message:

Module not found: Can't resolve 'redux' in 'C:\Users\Admin\Documents\projects\Web_projects\myapp\myapp\src'

Any advise is highly appreciated.

Edit: I ran

npm install --save redux

now the error message changed to:

./src/App.js
Module not found: Recursion in resolving
Mr. Engineer
  • 215
  • 1
  • 9
  • 26
  • Do you know which file specifically is giving you that error? Did you do something funky in webpack? – jmargolisvt Mar 07 '21 at 16:15
  • There are only two files involved: App.js and cart.js. This error occurs on front page after starting development server with "npm start". – Mr. Engineer Mar 07 '21 at 16:19
  • Does this answer your question? [Module not found: 'redux'](https://stackoverflow.com/questions/40082477/module-not-found-redux) – 0stone0 Mar 07 '21 at 16:23
  • @0stone0 Well I reinstalled redux specifically, now the error message changed: Module not found: Recursion in resolving – Mr. Engineer Mar 07 '21 at 16:28

1 Answers1

0

Found the solution: deleted redux from package.json and then reinstalled it. It seems that I had accidentally messed up package.json by installing react-redux before redux.

Mr. Engineer
  • 215
  • 1
  • 9
  • 26