[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available.
问题描述:
升级脚手架 vue-cli 4.5.15 版本之后,使用 template 时报错:
[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 项目有两种模式:Runtime+compiler模式 和 Runtime-only 模式,vue 模块的 package.json 的 main 字段默认为 Runtime-only 模式,指向“dist/vue/runtime.common.js”位置。
解决办法1:
在vue.config.js文件内加上 webpack 的如下配置:
module.exports = { // webpack配置 - 简单配置方式 configureWebpack: { resolve: { alias: { "vue$": "vue/dist/vue.esm.js", //加上这一句 } } } }
也就是将
import Vue from "vue"
这行代码被解析为:
import Vue from "vue/dist.vue.esm.js"
指定了文件的位置。没有使用 main 字段默认的文件位置。
或者
可以直接把 main.js 中的
import Vue from 'vue' //改成
import Vue from "vue/dist.vue.esm.js"
解决办法2:
我们可以修改模式,指定vue项目模式为:Runtime+compiler模式
vue.config.js 中的配置文件为:
module.exports = { runtimeCompiler:true }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?