简体   繁体   English

无法解决 React Native Redux 工具包中的模块错误

[英]Unable to resolve module Error in React Native Redux Toolkit

I am getting some weird error on adding Redux Provider in my App.tsx.在我的 App.tsx 中添加 Redux Provider 时出现一些奇怪的错误。 I have all modules installed and did the "delete node_modules folder and npm install " process already, still can't figure out the issue我已经安装了所有模块并执行了“删除 node_modules 文件夹和 npm 安装”过程,但仍然无法解决问题

Unable to resolve module ../../../../src/redux from
MY_PROJECT_PATH\node_modules\@reduxjs\toolkit\dist\redux-toolkit.cjs.production.min.js:

App.tsx应用程序.tsx

import { Provider as ReduxProvider } from "react-redux";
import { NavigationContainer } from "@react-navigation/native";
import BottomTabs from "./src/containers/BottomTabs";
import { store } from "./src/redux/store";

export default function App() {
  return (
    <ReduxProvider store={store}>
      <NavigationContainer>
        <BottomTabs />
      </NavigationContainer>
    </ReduxProvider>
  );
}

store.ts商店.ts

import { configureStore } from "@reduxjs/toolkit";
import themeReducer from "./themeSlice";

export const store = configureStore({
  reducer: {
    theme: themeReducer,
  },
});

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

themeSlice.ts主题切片.ts

import { createSlice } from "@reduxjs/toolkit";
import { DEFAULT_DARK_THEME } from "../theme/DefaultDarkTheme";
import {
  DEFAULT_LIGHT_THEME,
  DEFAULT_LIGHT_THEME_ID,
} from "../theme/DefaultLightTheme";
const messageSlice = createSlice({
  name: "theme",
  initialState: DEFAULT_LIGHT_THEME,
  reducers: {
    toggleTheme(state) {
      if (state.id === DEFAULT_LIGHT_THEME_ID) return DEFAULT_DARK_THEME;
      return DEFAULT_LIGHT_THEME;
    },
  },
});

export const { toggleTheme } = messageSlice.actions;
export default messageSlice.reducer;

check your "dependencies" in package.json you'll figure it out there is no "@reduxjs/toolkit".检查 package.json 中的“依赖项”,您会发现没有“@reduxjs/toolkit”。 just terminate all the process and add "reduxjs/toolkit" first.只需终止所有进程并首先添加“reduxjs/toolkit”。

by doing "yarn add @reduxjs/toolkit" or you can also go with npm通过执行“yarn add @reduxjs/toolkit”或者你也可以 go 和 npm

hope this will help you希望对你有帮助

did you find how to fix this?你找到解决方法了吗? I'm getting the same error:/我得到了同样的错误:/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM