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

在升级脚手架到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‘

原文地址:https://www.cnblogs.com/wpcnblog/p/11356520.html

时间: 2024-08-02 08:40:05

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

[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 包导出的是运行时构建,即 runtime 版本,不支持编译 template 模板. vue 在初始化项目配置的时候,有两个运行环境配置的版本:Compiler 版本.Runtime 版本. 其主要区别在于: Compiler 版本:可以对 template 模板内容进行编译(包括字符串模板和可以绑定的 html 对

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

报错信息如下图: 报错原因是:vue有两种形式的代码:一种是compiler(模版),另一种是runtime(运行时)模式. 修改方法:修改main.js ,对照自己的代码模式对号入座 原文地址:https://www.cnblogs.com/wpcnblog/p/11356495.html

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

roject facets做什么用? http://baike.baidu.com/view/6257360.htm,其实我感觉,就是让我们在创建项目时候,可以独立定义一个有一个模板供我们使用,在里面定义各种用到服务的版本,你在导入从其他地方拿过来的项目时候,需要修改项目与project facets的编译环境一致. 牛人博客:(有详细解释jdk compile与build path) http://blog.csdn.net/shan9liang/article/details/1726651

[Nuxt] Build a Vue.js Form then use Vuex Actions to Post to an API in Nuxt

The default behavior of submitting an HTML form is to reload the page. You can use the Vue.js @submit.prevent syntax to avoid that behavior. Then wire together the @submitevent with an add Vuex action to handle an async post to an api. This lesson wa

uniapp报错:vue.runtime.esm.js:619 [Vue warn]: Invalid prop: type check failed for prop &quot;count&quot;. Expected Number with value 1, got String with value &quot;1&quot;.

这是组件内报错,将Type类型改为[Number, String]即可 props: { count: { type: Number, default: 0 }, } 改为 props: { count: { type: [Number, String], default: 0 }, } 原文地址:https://www.cnblogs.com/wanggang2016/p/12388382.html

Runtime Only和Runtime + Compiler

如果你需要在客户端编译模板 (比如传入一个字符串给 template 选项,或挂载到一个元素上并以其 DOM 内部的 HTML 作为模板),就将需要加上编译器,即完整版 当使用 vue-loader 或 vueify 的时候,*.vue 文件内部的模板会在构建时预编译成 JavaScript.你在最终打好的包里实际上是不需要编译器的,所以只用运行时版本即可— 官方文档 客户端编译模板 1 <script src="https://cdn.jsdelivr.net/npm/[email pr

[转] 编译输出文件的区别

Vue 源码是选用了 rollup 作为 bundler ,看 Vue 的源码时发现: npm script 对应了不同的构建选项.这也对应了最后打包构建后产出的不同的包. 不同于其他的 library , Vue 为什么要在最后的打包构建环节输出不同类型的包呢?接下来我们通过 Vue 的源码以及对应的构建配置中简单的去分析下. 由于 Vue 是基于 rollup 进行构建的,我们先来简单了解下 rollup 这个 bundler : rollup 是默认使用 ES Module 规范而非 Co

【bug】vue-cli 3.0报错的解决办法

先上bug图片 bug说明:初装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源码探究-虚拟DOM的渲染

Vue源码探究-虚拟DOM的渲染 在虚拟节点的实现一篇中,除了知道了 VNode 类的实现之外,还简要地整理了一下DOM渲染的路径.在这一篇中,主要来分析一下两条路径的具体实现代码. 按照创建 Vue 实例后的一般执行流程,首先来看看实例初始化时对渲染模块的初始处理.这也是开始 mount 路径的前一步.初始包括两部分,一是向 Vue 类原型对象上挂载渲染相关的方法,而是初始化渲染相关的属性. 渲染的初始化 下面代码位于vue/src/core/instance/render.js 相关属性初始