0

I have a Webpack project, and I want to use Vue in it. I'm importing Vue in my JavaScript file like this:

import "../../node_modules/vue/dist/vue.min.js";

I can see vue.min.js in my bundle, but when I try to instantiate Vue in my HTML file or JavaScript file like this:

var app = new Vue({
  el: ‘#app’,
  data: {
    message: ‘Hello Vue!’
  }
})

I get this error in the console:

Uncaught ReferenceError: Vue is not defined
    at eval (ins.js?be14:2)
    at Object../src/scripts/ins.js (app.js:485)
    at __webpack_require__ (app.js:79)
    at eval (index.js?48f5:1)
    at Module../src/scripts/index.js (app.js:474)
    at __webpack_require__ (app.js:79)
    at Object.0 (app.js:530)
    at __webpack_require__ (app.js:79)
    at checkDeferredModules (app.js:46)
    at app.js:152

I tried to add vue.min.js directly in my HTML via CDN, and everything works fine. Is there is some ordering problem on load? How do I solve this problem?

1 Answer 1

3

You should import Vue to a variable like this:

import Vue from 'vue'; // or import Vue from '../../node_modules/vue/dist/vue.min.js';

It should then work with your example:

import Vue from 'vue';

var app = new Vue({
  el: ‘#app’,
  data: {
    message: ‘Hello Vue!’
  }
})
Sign up to request clarification or add additional context in comments.

1 Comment

@user3348410 No problem ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.