在升级脚手架到vue-cli3.0版本的时候出现了这个报错:

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

我在这里大概说一下出现这个报错的原因在哪里和解决办法
原因

vue有两种形式的代码 compiler(模板)模式和runtime模式(运行时),vue模块的package.json的main字段默认为runtime模式, 指向了"dist/vue.runtime.common.js"位置。

这是vue升级到2.0之后就有的特点。

而我的main.js文件中,初始化vue却是这么写的,这种形式为compiler模式的,所以就会出现上面的错误信息

// compiler
new Vue({
el: '#app',
router: router,
store: store,
template: '<App/>',
components: { App }
})

解决办法

将main.js中的代码修改如下就可以

//runtime

new Vue({
router,
store,
render: h => h(App)
}).$mount("#app")

到这里我们的问题还没完,那为什么之前是没问题的,之前vue版本也是2.x的呀?

这也是我要说的第二种解决办法

因为之前我们的webpack配置文件里有个别名配置,具体如下

resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' //内部为正则表达式 vue结尾的
}
}

也就是说,import Vue from ‘vue’ 这行代码被解析为 import Vue from ‘vue/dist/vue.esm.js’,直接指定了文件的位置,没有使用main字段默认的文件位置

所以第二种解决方法就是,在vue.config.js文件里加上webpack的如下配置即可,

configureWebpack: {
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}

既然到了这里我想很多人也会想到第三中解决方法,那就是在引用vue时,直接写成如下即可

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

You are using the runtime-only build of Vue where the template compiler is not available. Either pre的更多相关文章

  1. You are using the runtime-only build of Vue where the template compiler is not available.

    使用vue-cli搭建的项目,启动报错 You are using the runtime-only build of Vue where the template compiler is not a ...

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

    异常 You are using the runtime-only build of Vue where the template compiler is not available. Either ...

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

    转载自:https://segmentfault.com/a/1190000006435886 解决办法:添加package.config.js配置文件中,添加本文章的红色部分代码 import vu ...

  4. [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available

    原文链接https://blog.csdn.net/xiaomajia029/article/details/88320233 问题描述: 原因分析:在项目配置的时候,默认 npm 包导出的是运行时构 ...

  5. Vue项目用了脚手架vue-cli3.0,会报错You are using the runtime-only build of Vue where the template compiler is not available.....

    摘自: https://blog.csdn.net/wxl1555/article/details/83187647 报错信息如下图: 报错原因是:vue有两种形式的代码:一种是compiler(模版 ...

  6. Vue Cli 报错:You are using the runtime-only build of Vue where the template compiler is not availabl

    报错原因: 这里引用的是vue.runtime.esm.js,造成的不能正常运行. vue-cli 2.x 解决方法: 在webpack.base.conf.js配置文件中多加了一段代码,将 vue/ ...

  7. vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed for prop "value".报错解决

    在uni中使用 picker组件,一直报错 vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed ...

  8. eclipse中build path 中JDK与java compiler compliance level的问题(转)

    roject facets做什么用? http://baike.baidu.com/view/6257360.htm,其实我感觉,就是让我们在创建项目时候,可以独立定义一个有一个模板供我们使用,在里面 ...

  9. WebStorm 使用webpack打包(build) Vue 静态资源无法访问(路径不对)问题

    在WebStorm中使用webpack打包 (命令npm run build) 后生成在项目的dist目录下,在浏览器打开,静态资源js.css等无法加载.因为打包时,资源使用了绝对路径. 解决: 打 ...

随机推荐

  1. jenkins安装和简单部署

    jenkins安装和简单部署 jenkins历史 jenkins是一款非常好用的团队CI(Continuous Integration)工具.它可以使你的构建,集成,发布,开发流程自动化.减轻各个环节 ...

  2. k8s安装之nginx.yaml

    这里两个nginx.一个是用来测试最简单的集群的. 另一个是用来作grafana,prometheus,dashboard前端安全展示的. 简单版 apiVersion: apps/v1 kind: ...

  3. linux系统编程之管道(二)

    今天继续研究管道,话不多说,言归正传: 对于管道,有一定的读写规则,所以这里主要是对它的规则进行探讨,具体规则如下: 规则一: 下面用程序来验证下,还是用上节学的子进程写数据,父进程读取数据的例子,只 ...

  4. 小程序基础能力~自定义 tabBar

    自定义 tabBar 基础库 2.5.0 开始支持,低版本需做兼容处理. 自定义 tabBar 可以让开发者更加灵活地设置 tabBar 样式,以满足更多个性化的场景. 在自定义 tabBar 模式下 ...

  5. P2261 [CQOI2007]余数求和[整除分块]

    题目大意 给出正整数 n 和 k 计算 \(G(n, k)=k\ \bmod\ 1 + k\ \bmod\ 2 + k\ \bmod\ 3 + \cdots + k\ \bmod\ n\) 的值 其中 ...

  6. csr_matrix

    from scipy.sparse import * row = [0,0,0,1,1,1,2,2,2]#行指标col = [0,1,2,0,1,2,0,1,2]#列指标data = [1,0,1,0 ...

  7. workerman——消息推送(web-msg-send)

    前言 说下场景,当后台将号码池的号码分配给指定客服的时候,需要给指定的客户推送一条消息告诉该客户,通讯录有新增数据. 步骤 下载 https://www.workerman.net/web-sende ...

  8. 1-html基本结构与编写规范

    <!DOCTYPE html> <html> <!-- #前端开发系统化学习教程, #包括html.css.pc端及移动端布局技巧.javascript. #jquery ...

  9. 错误信息: The server cannot or will not process the request due to something that is perceived to be a client error

    错误原因:在提交的表单中有 date 类型的数据,也就是不能传输日期类型的数据. 嗯!我知道,去吧!

  10. SIGAI机器学习第二十二集 AdaBoost算法3

    讲授Boosting算法的原理,AdaBoost算法的基本概念,训练算法,与随机森林的比较,训练误差分析,广义加法模型,指数损失函数,训练算法的推导,弱分类器的选择,样本权重削减,实际应用. AdaB ...