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

calebporzio's avatar

Error: "Vue is not defined"

I can use vue if I include the compiled javascript at the end of the body, but if I attempt to use it the @JeffreyWay way I get this error: "Uncaught ReferenceError: Vue is not defined"

I installed vue via: npm install vue --save I included it via: var Vue = require('vue'); using browserify in elixir: mix.browserify('app.js'); I included it in the body using:

Here is my test code for it:

var registration = new Vue({
        data: {
            email: ''
        }
    }).$mount('#registration-form');

Any help is appreciated, thanks!

0 likes
9 replies
thomaskim's avatar

Can you post the entire file, not just that snippet?

jimmck's avatar

Make sure JS page is loaded when you create the Vue object.

jimmck's avatar

Also $mount will get called for you. Its no bigee Vue will throw a warning if it has already compiled your DOM. I have an initialize function which called from my Layout blade. That function is in the included JS file for the App.

function setupEvents() {
    console.log("Coverage: " + this);
    app = app = new Vue({
        el: '#app-container',

        data: {
            shortName: "",
            longName: "",
            //selectOptions: [new Option("1", 1), new Option("2", 2)],
            selectOptions: [],
            selected: -1,
        },
...

If you wanted to build a Vue object as in the demo. The app variable is just a Global (Oh My!!!) to the whole script.

calebporzio's avatar

@jimmck: the app.js file is loaded before I create the new Vue instance.

This is puzzling me.

It goes:

<script src="app.js"></script>
<script>
    new Vue({ ... });
</script>

Here is end of the app.js file from chrome dev tools:

module.exports = Watcher

}).call(this,require('_process'))
},{"./batcher":8,"./config":14,"./observer/dep":48,"./parsers/expression":52,"./util":63,"_process":1}],68:[function(require,module,exports){
'use strict';

var Vue = require('vue');

},{"vue":66}]},{},[68]);
jimmck's avatar

Yes. Same issue as with me. Hence the console.log message at the top of my example snippet cuz my Vue object was null. Your doing Node coding??? My issue was Browser. But same deal. You want to make sure the Vue object gets initialized in correct scope.

1 like
calebporzio's avatar

Thanks @thomaskim and @jimmck.

I added:

window.Vue = Vue;

to my browserified javascript file to make it accessible globally. Worked like a charm.

3 likes
jerlandsson's avatar

If you don't mind, I hijack this thread a bit...

I try to do just as you've done above (window.Vue = Vue that is), but I get Vue is not defined. I'm using webpack, but that shouldn't matter, right? If it's defined in the window-object it should be reachable from other files further down the rabbit hole, right?

1 like
deepesh's avatar

Attach jquery, it resolves the problem.

1 like

Please or to participate in this conversation.