2

I am starting with Vue.js, and I am wondering how to import it properly, in order to bundle it with Webpack. All the examples in the documentation seem to assume that a Vue object is already present.

This is what I tried:

const Vue = require('vue')

and also

const Vue = require('vue').Vue

and then

var app = new Vue({ <options> })

This file is then bundled with Webpack and referenced in my HTML index file. But I am getting this error in the browser (in both cases):

Uncaught TypeError: Vue is not a constructor

2
  • 1
    Why not using Vue CLI ? Check this guide
    – Fabjan
    Commented Nov 12, 2019 at 17:41
  • @Fabjan Thanks, I have seen that. I would prefer to keep my existing Webpack build, which I have just set up. See the about-to-get-accepted answer. Commented Nov 12, 2019 at 19:11

1 Answer 1

2

I think the best way, if you are using ES6, is to use

import Vue from 'vue';
var app = new Vue({ <options> })
4
  • This looks better, I was not even aware that import and require would work differently. Now I am getting this error: "[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build." Do you know how to fix that also? Commented Nov 12, 2019 at 17:44
  • I think you still have to install and configure vue template compiler with WebPack vuejs.org/v2/guide/…
    – Synamatics
    Commented Nov 12, 2019 at 17:46
  • If you solved the issue, please accept as answer! Cheers!
    – Synamatics
    Commented Nov 12, 2019 at 18:34
  • That last link you sent part, the Webpack section, is presumably what I have been missing. I will not forget to accept your answer once I verified it. This seems to be the solution that I am looking for in the context of my existing Webpack build. Commented Nov 12, 2019 at 19:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.