Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
How do I solve __WEBPACK_IMPORTED_MODULE_1__.default is undefined

I am trying to use the token from my redux store inside my Axios instance. I tried importing the store but I am getting the and error saying _app_store__WEBPACK_IMPORTED_MODULE_1__.default is undefined. Please how do I solve this?

This is my code.

store.js



    import { configureStore, combineReducers } from "@reduxjs/toolkit";
    import authReducer from "../features/auth/authSlice";
    import cartReducer from "../features/cart/cartSlice";
    
    import {
      persistReducer,
      FLUSH,
      REHYDRATE,
      PAUSE,
      PERSIST,
      PURGE,
      REGISTER,
    } from "redux-persist";
    import storage from "redux-persist/lib/storage";
    
    const persistConfig = {
      key: "root",
      storage,
    };
    
    const reducers = combineReducers({
      auth: authReducer,
      cart: cartReducer,
    });
    
    const persistedReducer = persistReducer(persistConfig, reducers);
    
    const store = configureStore({
      reducer: persistedReducer,
      middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware({
          serializableCheck: {
            ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
          },
        }),
    });
    
    export default store;


Then this is my axios instance file.

api.js



    import axios from "axios";
    import store from "../app/store";
    
    const token = store.getState().auth.token;
    
    const api = axios.create({
      baseURL: process.env.REACT_APP_API_URL,
      headers: {
        Authorization: token,
      },
    });
    
    export default api;


about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Apparently, I was trying to use the store before it was initialized. So I just created an interceptor for the Axios instance and called the store in there.

api.js



    import axios from "axios";
    import store from "../app/store";
    
    const api = axios.create({
      baseURL: process.env.REACT_APP_API_URL,
    });
    
    api.interceptors.request.use((config) => {
      const token = store.getState().auth.token;
      config.headers = {
        Authorization: token ? `Bearer: ${token}` : null,
      };
      return config;
    });
    
    export default api;



about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda