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

marcellopato's avatar

create:925 Uncaught ReferenceError: axios is not defined

I updated my Laravel app from 5.5 to 5.6 to 5.7 but axios stops working I've deleted node_modules dir, npm install, npm axios install, etc. but still got the error!

"devDependencies": {
        "axios": "^0.18.0",
        "bootstrap-sass": "^3.4.1",
        "cross-env": "^5.2.0",
        "jquery": "^3.3.1",
        "laravel-mix": "4.0.15",
        "lodash": "^4.17.11",
        "resolve-url-loader": "2.3.1",
        "sass": "^1.17.3",
        "sass-loader": "7.*",
        "vue": "^2.6.9",
        "vue-template-compiler": "^2.6.9"
    },

My bootstrap file is ok, like:


window.axios = require('axios');

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

So, what could be wrong?

P.S.: When I run npm outdated, nothing appears.

0 likes
6 replies
tykus's avatar

Are you requiring thebootstrap.js into your app.js? Also, that error appears like you are using axios directly in a script tag on your blade view - are you perhaps trying to use axios before the app.js is loaded on the page; check the order of your scripts?

marcellopato's avatar

@TYKUS - No, it is just the way it should be. By the way, it used to work after the Laravel updates...

Snapey's avatar

check your scripts imports in the layout file for the defer attribute

eg

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

You might need to wrap your javascript in window.load()

marcellopato's avatar

@MUNAZZIL - Did it. And run npm dev.

pegaCep() {
                const vm = this
                axios.get('cep?c='+this.cep)
                .then(function (response) {
                    vm.bairro = response.data.bairro,
                    vm.complemento = response.data.complemento,
                    vm.localidade = response.data.localidade,
                    vm.logradouro = response.data.logradouro,
                    vm.uf = response.data.uf
                });
            }
Uncaught ReferenceError: axios is not defined
    at Vue.pegaCep (create:925)
    at boundFn (vue.js:188)
    at HTMLInputElement.invoker (vue.js:1820)

What a heck?

Please or to participate in this conversation.