Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTK 2.4.0 Runtime Error: Unable to resolve module ../../../../../src/redux from ../node_modules/@reduxjs/toolkit/dist/cjs/redux-toolkit.development.cjs: #4741

Open
isharadilshan opened this issue Nov 30, 2024 · 4 comments

Comments

@isharadilshan
Copy link

isharadilshan commented Nov 30, 2024

I'm encountering a runtime error when using the newest version of "@reduxjs/toolkit": "^2.4.0" in my React Native application. Downgrading to the previous stable version "@reduxjs/toolkit": "^2.3.0" resolves the issue.

Package versions:

"@reduxjs/toolkit": "^2.4.0",
"react": "18.3.1",
"react-native": "0.76.3",
"react-redux": "^9.1.2",
"redux-logger": "^3.0.6"

Store Configuration file:

import {combineReducers, configureStore} from '@reduxjs/toolkit';
import logger from 'redux-logger';
//Base API
import {baseApi, middleware} from '../api/baseApi';
//reducers
import {productReducer} from '@redux/slices';

const isDevMode = process.env.NODE_ENV === 'development';

const rootReducer = combineReducers({
  [baseApi.reducerPath]: baseApi.reducer,
  product: productReducer,
});

// Configure the Redux store
export const store = configureStore({
  reducer: rootReducer,
  middleware: getDefaultMiddleware =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [],
      },
    }).concat(isDevMode ? [logger, middleware] : [middleware]),
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

App Setup:

import React from 'react';
import type {ReactNode} from 'react';
import {PaperProvider} from 'react-native-paper';
//redux
import {Provider} from 'react-redux';
import {store} from '../redux/store';
//navigator
import Navigator from '../navigation';

const App: () => ReactNode = () => {
  return (
    <Provider store={store}>
      <PaperProvider>
        <Navigator />
      </PaperProvider>
    </Provider>
  );
};

export default App;

Temporary Solution:

Downgrading to @reduxjs/toolkit": "^2.3.0"resolves the issue.

Image

@phryneas
Copy link
Member

If you look at that file it only contains require("redux") calls. Do you maybe have a redux folder in your app somewhere? That sometimes confuses bundlers to look for that folder instead of the package with the similar name.

@markerikson
Copy link
Collaborator

markerikson commented Nov 30, 2024

Also, it seems very odd that this would only manifest in 2.4.0. We didn't change anything about the bundling or build setup in this release.

For that matter, it's very suspicious that the path shown includes ../src/redux. A node_modules import shouldn't end up pointing to anything with src in the path.

@isharadilshan
Copy link
Author

@phryneas @markerikson I named my folder as reduxstore for my Redux code. Could this cause any issues?

@markerikson
Copy link
Collaborator

@isharadilshan that doesn't seem related, but the @redux/ in your imports might be.

Either way this is presumably an issue with your build setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants