3

I got a React-app project in which I installed npm and Redux Toolkit.

After having added a store provider for the whole app in this way

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';

import './index.css';
import App from './App';
import store from './store/index';

ReactDOM.render(<Provider store={store}><App /></Provider>, document.getElementById('root'));

if I npm start the app I get this error:

Module not found: Can't resolve 'react-redux' in '/Desktop/React/redux-app/src'

I've read on the official Redux site:

Redux Toolkit includes the Redux core, as well as other key packages we feel are essential for building Redux applications

So I guess that having Redux Toolkit alone should be enough to resolve any react-redux module.

I noticed that my package.json and package-lock.json are in the directory from which I run npm start, that is /redux-app while the module is not found in /redux-app/src. Is that fine? Should I move the .json files? How can I fix the problem in general?

2
  • 1
    redux core and react-redux are different things. Have you tried installing react-redux separately? Commented May 8, 2021 at 18:11
  • @jmargolisvt No I haven't, so react toolkit alone is not enough? I should always install also react-redux? Commented May 8, 2021 at 18:20

2 Answers 2

8

React-Redux isn't part of the Redux core.

Redux Toolkit includes the Redux core, as well as other key packages we feel are essential for building Redux applications

Redux isn't React specific, it works with whatever stack you want to try it with. When working with Redux and React, you will want to install and use React-Redux to get it working better with React. You don't necessarily need to, but it helps a lot.

In this case, it's focusing on applications that use redux. It's a toolkit that drastically improves the use of redux in particular. It doesn't care what you try and use redux with, so it won't affect the binding logic between react and redux (the react-redux package).

A good test for this is if there's a different base package name you are trying to pull the code in from, you should install that other package (even if it appears to work). i.e. import {} from 'react-redux' vs import {} from '@reduxjs/toolkit.

In answer to your question, you'll need to run npm install react-redux from your base directory (/redux-app). You shouldn't move your .json files around from where they are. They are meant to be in the root of your project.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh you are right Redux isn't just for React, so it's understandable that Redux Toolkit doesn't include React stuff. I installed react-redux and the app works. Thank you. The question now seems a bit awful, but I'll leave it, maybe someone else will have the same doubt.
-1

If you use npm:

npm install react-redux

Or if you use Yarn:

yarn add react-redux

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.