'How can i solve Module not found: Error: Can't resolve './reducers' while setting rootReducer in redux

I am trying to configure redux with my react app. While configuring rootReducer I am facing this error: Module not found: Error: Can't resolve './reducers'

Here is my code:

import React from 'react';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import rootReducer from './reducers';
import { configureStore } from '@reduxjs/toolkit';

const store = configureStore({ reducer: rootReducer })

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

Here is my folder structure and files screenshot https://ibb.co/ZVbLh9S

What am I missing?

Thanks in Advance.



Solution 1:[1]

It seems like there is no file called reducers.js. But you have a usersSlice.js - are you taking things from multiple different tutorials here? In that case, please follow only one, from start to end, preferrably the official tutorial.

As for your problems - assuming this is your store.js and your userSlice.js contains export default slice.reducer, do the following:


import usersReducer from './usersSlice';

// ....


const store = configureStore({ 
  reducer: {
    users: usersReducer
  }
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 phry