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

saluei's avatar

bootstrap.js error window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'

after upgrading from laravel 8 to 9.46 in application startup (in login page) I encountered the error

Paused on exception:
TypeError: can't access property "headers", window.axios.defaults is undefined

exception is in bootstrap.js file in bellow line

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

I changed that line to the:

window.axios.default.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

and problem solved.

But I do not know WHY the problem solved , and whether this is correct solution ? any comment appreciated. this is my package.json:

 "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_OPTIONS=--openssl-legacy-provider NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^1.1.2",
        "bootstrap": "^4.0.0",
        "cross-env": "^7.0",
        "jquery": "^3.2",
        "laravel-mix": "^5.0.1",
        "lodash": "^4.17.19",
        "popper.js": "^1.12",
        "resolve-url-loader": "^3.1.0",
        "sass": "^1.15.2",
        "sass-loader": "^8.0.0",
        "vue-template-compiler": "^2.6.11"
    },
    "dependencies": {
    }

and composer.json

 "require": {
        "php": "^8.1",
        "fideloper/proxy": "^4.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.19",
        "laravel/tinker": "^2.7",
        "laravel/ui": "^4.0",
        "simplesoftwareio/simple-qrcode": "^4.2",
        "stechstudio/laravel-zipstream": "^4.8"
    },
    "require-dev": {
        "fakerphp/faker": "^1.16.0",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.0"
    },
0 likes
1 reply
Nakov's avatar
Nakov
Best Answer
Level 73

Here is the discussion on when it happened: https://github.com/axios/axios/issues/5044

and the solution you are mentioning can either be added there or when you are requiring the axios library and setting it to the windows object.

Please or to participate in this conversation.