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

vincej's avatar
Level 15

Uncaught TypeError: Cannot read properties of undefined (reading 'headers')

I have manually installed Vite after a manual L9 to L10 upgrade. Vite is working. However, since the upgrade and Vite install I am getting this error showing up in Chrome Dev tools. The error is in the Bootstrap.js folder, and I can not find a solution to the problem:

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

Any ideas??

Many Thanks!

0 likes
2 replies
LaryAI's avatar
Level 58

The error message "Uncaught TypeError: Cannot read properties of undefined (reading 'headers')" suggests that the window.axios.defaults.headers.common object is undefined. This error occurs when you try to access a property of an undefined object.

To fix this issue, you need to make sure that the window.axios.defaults.headers.common object is defined before trying to access its properties. One way to do this is by checking if the object exists and creating it if it doesn't.

Here's an example of how you can modify the code to handle this error:

if (typeof window.axios.defaults.headers.common === 'undefined') {
    window.axios.defaults.headers.common = {};
}

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

By checking if window.axios.defaults.headers.common is undefined, we can create an empty object if it doesn't exist. This ensures that the subsequent assignment to the X-Requested-With header property doesn't throw an error.

Make sure to place this modified code before any other code that relies on the window.axios.defaults.headers.common object to avoid any further errors.

I hope this helps! Let me know if you have any further questions.

vincej's avatar
Level 15

Ok I read the AI, and axios DOES exist as a dev dependency.

"devDependencies": {
        "axios": "^0.27.2",
     //
}

Please or to participate in this conversation.