question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue.compile is not a function

See original GitHub issue

I am using Vuejs 2 (webpack-simple template) and I would compile template before render it. Below my code : App.vue

<template>
    <div id="app">
        <h1>{{ msg }}</h1>
    </div>
</template>
<script>
    export default {
        name: 'app'
    }
</script>

main.js

import Vue from 'vue'
import App from './App.vue'

const res = Vue.compile(App)
const vm = new Vue({
    el: '#app',
    data: {
        msg: 'hello'
    },
    render: res.render,
    staticRenderFns: res.staticRenderFns
})

But when I start the server I got this error : __WEBPACK_IMPORTED_MODULE_0_vue___default.a.compile is not a function . Can you please help me to make it work ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
LinusBorgcommented, Oct 18, 2016

So, If I keep just the content inside the <template> tag in my ‘App’ component, is there any way to get its content as String in main.js ?

No. The whole point of vue files is to keep everything in one place. Why do you want an App.vue component if you only want the template string?

I don’t really understand what you are trying to do, or why, despite your explanation. Sorry 😦

Maybe save it as .html and install html-loader to do template: require('html!./main.html')

2reactions
LinusBorgcommented, Oct 18, 2016

import Vue from 'vue'imports the runtime-only build, which does not have the compiler.

https://vuejs.org/guide/installation.html#Standalone-vs-Runtime-only-Build

I will adjust the template to include the standalone build version by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuejs, Universal app, compile is not a function - Stack Overflow
If I build the application as SPA (mode: 'spa'), it can works, but doesn't work for universal mode. I guess it's because the...
Read more >
Vue.compile is not a function error when publishing ...
compile is not a function error when publishing component as a package. Hello, I've created the following simple component which i published on...
Read more >
Vuejs, Universal app, compile is not a function - Get Help
I have vuejs application, build with nuxt cli. One vue component needs to load dynamic template, then compile on the fly.
Read more >
vue compile render function from a template
In vuejs there is the vue compile global api method that can be used to compile a template string into an object that...
Read more >
How to use the vue.compile function in vue - Snyk
it('should be able to bind scroll function', async () => { const res = Vue.compile('<div v-scroll="onScroll"></div>') const vm = new Vue({ data ()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found