Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails + webpacker + vue: "You are using the runtime-only build of Vue where the template compiler is not available."

I've created a new rails 5.2 application and installed vue with:

bundle exec rails webpacker:install:vue

After creating a simple endpoint Home#landing and adding <%= javascript_pack_tag 'hello_vue' %> to the default layout the sample app is working as expected.

I made a few changes:

1) Modified hello_vue.js to,

import Vue from 'vue'

document.addEventListener('DOMContentLoaded', () => {
  const app = new Vue({
    el: '#vueapp',
    data: {
      message: "Hello Vue!"
    }
  })
})

2) Created and empty <div id="vueapp"> {{ message }} </div> at the only view I have.

3) Removed app.vue from app/javascripts.

As far as I know, that should work too (and is how we were working with the vue-rails gem that runs with sprockets). Now is failing with:

[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.

I cannot exactly understand what is happening or why is failing because there aren't any components or template to compile at my app.

like image 760
pragmatic_programmer Avatar asked May 22 '18 17:05

pragmatic_programmer


1 Answers

The default export for the vue NPM package is the runtime only.

As you need the template compiler, you need to change your Vue import to the following, which includes both the runtime and the template compiler:

import Vue from 'vue/dist/vue.esm.js';

More details: here https://vuejs.org/v2/guide/installation.html#Explanation-of-Different-Builds

like image 95
nstCactus Avatar answered Oct 08 '22 00:10

nstCactus