我收到一个与redux-persistent相关的错误:无法解决“react”

6bc51xsx  于 5个月前  发布在  React
关注(0)|答案(1)|浏览(79)

我正在使用redux-persist,我只是将其添加到'main.js'文件中,但我一直得到这个错误:
无法解决“react”

../node_modules/redux-persist/es/integration/react.js:
21:37:
      21 │ ...Component } from 'react'; // eslint-disa...
         │                     ~~~~~~~
         ╵                     "./react"

  Use the relative path "./react" to reference the file
  "../node_modules/redux-persist/es/integration/react.js".
  Without the leading "./", the path "react" is being
  interpreted as a package path instead.

字符串
我尝试修改node_modules/redux-persist/es/integration/react.js并将“import React,{ PureComponent } from 'react';”更改为“import React,{ PureComponent } from './react';”,因为它在错误中写入,但它不工作。我想我必须修复其他东西,但我不知道它是什么。
下面是我的代码:main.js文件:

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.jsx';
import './index.css';
import { persistor, store } from './redux/store.js';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';

ReactDOM.createRoot(document.getElementById('root')).render(
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistor}>
      <App />
    </PersistGate>
  </Provider>
);


store.js:

import { combineReducers, configureStore } from '@reduxjs/toolkit';
import userReducer from './user/userSlice';
import { persistReducer, persistStore } from 'redux-persist';
import storage from 'redux-persist/lib/storage';

const rootReducer = combineReducers({ user: userReducer });

const persistConfig = {
  key: 'root',
  storage,
  version: 1,
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

export const store = configureStore({
  reducer: persistedReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: false,
    }),
});

export const persistor = persistStore(store);

7tofc5zh

7tofc5zh1#

我跟你一样的教程(MERN Stack Modern Real Estate Marketplace),遇到了同样的问题. redux-persist包应该已经安装在客户端文件夹,而不是根文件夹.一旦安装在客户端文件夹,它被解决.你可以使用npm uninstall redux-persist从根文件夹卸载另外

相关问题