我在App.tsx中添加Redux提供程序时遇到了一些奇怪的错误。我已经安装了所有模块,并且已经完成了“删除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
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
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
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;
1条答案
按热度按时间kpbwa7wx1#
检查package.json中的"dependencies",你会发现没有"@reduxjs/toolkit "。只需终止所有进程并首先添加" reduxjs/toolkit "即可。
通过执行"yarn add@reduxjs/toolkit"或者也可以使用npm
我希望这对你有帮助