reactjs 在我的ApiClient助手的redux中找不到模块“store”[已关闭]

bnl4lu3b  于 2022-11-04  发布在  React
关注(0)|答案(1)|浏览(135)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
11小时前关门了。
Improve this question
这是一个应用程序从4年前,我试图让它在本地工作之前,我更新依赖关系.获取控制台错误找不到模块“商店”
src/helpers/ApiClient.js

import axios from 'axios';

import { AUTH_USER_OUT } from 'store/modules/auth/types';
import getEnv from 'helpers/getEnv';

export class Api {
  static client = null;

  static init(store) {

    if (!Api.client) {
      Api.client = axios.create({
        baseURL: getEnv('REACT_APP_BACKEND_URL'),
      });

      Api.client.interceptors.request.use(config => {
        const newConfig = config;
        const {
          auth: { token },
        } = store.getState();

        newConfig.headers.authorization = token;

        return newConfig;
      });

      Api.client.interceptors.response.use(
        response => response,
        error => {
          if (error.response.status === 401) {
            store.dispatch({
              type: AUTH_USER_OUT,
            });
          }
          return Promise.reject(error);
        },
      );
    }
  }
}

错误消息为

Module not found: Can't resolve 'helpers/ApiClient' in

控制台错误:

Uncaught Error: Cannot find module "store"
s4n0splo

s4n0splo1#

所以,这可能是由于许多原因:这可能是由于存储区的位置错误,您可以通过在VSCode中使用以下键来找到存储区:CTRL+SHIFT+F,然后在那里输入store,你会找到redux的存储,如果你在整个项目中没有找到,那么存储就不存在,你必须手动创建它。
但是,如果您发现,可能无法定义Auth_USER_OUT,此时您必须自行创建。

相关问题