Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ssquare's avatar

Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization

I am having issues while trying to add token on axios request.

I have not used default bootstrap.js provided by laravel itself (which contains the initializtion for axios as well).

I am trying to follow more like independent react architecture but with in the laravel. You could just consider that I have not included bootstrap.js but have created my own httpClient.js and it looks like this:

import axios from "axios";
import auth from "../services/authService";

axios.defaults.headers.common['Content-Type'] = 'application/json';
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
if(auth.getJwt() != null){
    axios.defaults.headers.common["Authorization"] = "Bearer "+ auth.getJwt();
}

let client = axios.create({
    baseURL: 'https://laracms.test/api'
});


export default {
    get: client.get,
    post: client.post,
    put: client.put,
    delete: client.delete,
};
export function getJwt() {
    if(tokenKey in localStorage){
        return localStorage.getItem(tokenKey);
    }
    return null;
}

here, axios throws error when ever I tried to add Authorization headers line in above code

Whenever, I need to make api call I am planning to import this httpClient and then make api call with that. But, currently it is throwing error as:

app.js:3730 Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
    at Module.default (app.js:3730)
    at Module../resources/js/utils/httpClient.js (app.js:4288)
    at __webpack_require__ (app.js:54454)
    at Module../resources/js/services/authService.js (app.js:3734)
    at __webpack_require__ (app.js:54454)
    at Module../resources/js/components/auth/Login.jsx (app.js:2035)
    at __webpack_require__ (app.js:54454)
    at Module../resources/js/routes/routes.js (app.js:3614)
    at __webpack_require__ (app.js:54454)
    at Module../resources/js/AppComponent.js (app.js:1962)
0 likes
0 replies

Please or to participate in this conversation.