-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Failed to mount component: template or render function not defined. (found in root instance) #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for filling this issue. |
thank you |
I follow @fnlctrl advice to fix the vue template compiler. But another problem come out. All the get start vue code copy from get-start-page The different is webpack config.
And after the Can anyone give me some advice for this? That's mine fault, it's need more |
It works!!! good! |
Should I also use standalone build if I'm using Single File Components? |
@oleynikd No, single file components will have their templates compiled at build time. As long as you don't use the |
@fnlctrl so here is the problem. In main.js, which isn't a single file component so that can not be compiled, how can I declare the top component |
@xqyww123 If you're using the runtime-only build, anything put inside html cannot be compiled. Therefore, you'll need the A simple example: // your entry js
import App from './App.vue';
new Vue(App).mount('#app'); <body>
<div id="app"></div>
</body> If you need to add a // your entry js
import App from './App.vue';
import store from './store';
import router from './router';
new Vue({
...App // ES7 Object rest spread operator (or Object.assign)
router,
store
}).mount('#app'); The above is the javascript approach. // your entry js
import App from './App.vue';
import store from './store';
import router from './router';
new Vue({
router,
store,
render: h => h(App)
}).mount('#app'); |
@fnlctrl // index.html
// main.js
// result vue.runtime.common.js:519 [Vue warn]: Failed to mount component: template or render function not defined. |
No. That's not what I said. Let me rephrase that: since the runtime-only build cannot compile anything (in-dom, template string), you can't put templates inside html, so you either use |
For anyone still finding this thread, this is how I ended up getting past this error for my browserify and typescript setup:
|
@ubershmekel Not to take us too off-topic, but how do you get typings with that setup? |
If you're using Webpack 2 to build your application, here is what I did to resolve the problem: From
From there, you are able to install Vue as you would expect using ES6 syntax:
|
有中文的解答吗? 看得不是很明白 ?? |
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
component: require('../pages/Main.vue').default
}
]
}) if you use require in router, you need add a |
as @wspl commented, it would work well. another option is 'import' as following: import Vue from 'vue'
import Router from 'vue-router'
import Main from '../pages/Main.vue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
component: Main
}
]
}) |
删除你的module文件夹,重新更新安装所有依赖(使用npm进行安装)。请不要通过cnpm进行安装依赖,这会导致有些包找不到地址(无法正常找到)。推荐使用npm,更换镜像地址即可! |
一群中国人在这里用英语交流,也是醉了哈 |
@wspl thanks |
Smilar problem, when I write: let routes = [{ let routes = [{ |
@SageSanyue 你可以尝试使用webpack的动态导入语法: component: () => import ('./HelloWorld') const routes = [{
path: '/',
component: () => import('./components/member.vue')
}]
|
thank you @notescript |
@molerat619 你可以换一种提问题的方式? 期望 -> 现状 -> 结果 ---代码--- ---问题描述--- 你应该尽可能详细的描述你遇到的问题。 |
i ran into same issue, but my solution was this: i think it's same as in @molerat619 example |
In my case, I imported my component (in router) as:
It is simply solved if I changed it to
|
@askanhan solution worked perfect for me! Still I don't know why that caused the problem, the software I'm working on has been online for about 3 years and we are using Vue since 1 year ago but it worked fine :( |
I solve mine by adding default after closing curly bracket. '.default'. e.g. |
Couldn't find any reason but I believe it has something to do with the updates of webpack or so |
@wspl Thanks, thanks really all I needed to fix the error: [Vue warn]: Failed to mount component: template or render function not defined. |
@skinnn, maybe you must be missing default keyword when you use like that: require('./components/Example.vue').default |
I was getting the same error but adding .default helped as well. Here is my app.js in case it helps anyone else:
|
Adding .default works for me too. In case yours doesn't change after adding .default try recompiling your code (.eg. |
Adding .default at the end of component line and worked |
You can do
|
I got this error because I had empty |
I got blank on my web page. On console, I got this error ->Vue warn]: Failed to mount app: mount target selector "#app" returned null. I have used vue 3 with laravel 8 and used laravel-mix.I've added the bootstrap 5 but it is working on my laravel blade template but other vue component is not working. On blade
On app.js
on App.vue
|
@bhojkamal so by reading the error you should be able to tell what's wrong. Replace |
I write it in this case, but it is wrong.
http://router.vuejs.org/en/essentials/getting-started.html
The text was updated successfully, but these errors were encountered: