SyntaxError:?/xx.vue:?Unexpected?token,?expected?“,“錯(cuò)誤解決
錯(cuò)誤
本地老工程vue2.7.x+webpack4在升級(jí)webpack5的時(shí)候遇啟動(dòng)和打包報(bào)錯(cuò):
Syntax Error: SyntaxError: /xxxxx.vue Unexpected token, expected "," (1:8)
> 1 | [object Promise]
| ^
2 | export { render, staticRenderFns }最后才發(fā)現(xiàn)是prettier導(dǎo)致的。
推薦看看stackoverflow上面這個(gè)回答。Update Nodejs 14->18 — webpack have the same syntaxError: /.../xxx.vue: Unexpected token, expected "," (1:8) for ALL Vue 2 components in the project
導(dǎo)致原因
在prettier v3.0.0中,默認(rèn)值從es5更改為all
Default value changed from es5 to all in v3.0.0 Print trailing commas wherever possible in multi-line comma-separated syntactic structures. (A single-line array, for example, never gets trailing commas.) Valid options: "all" - Trailing commas wherever possible (including function parameters and calls). To run, JavaScript code formatted this way needs an engine that supports ES2017 (Node.js 8+ or a modern browser) or downlevel compilation. This also enables trailing commas in type parameters in TypeScript (supported since TypeScript 2.7 released in January 2018). "es5" - Trailing commas where valid in ES5 (objects, arrays, etc.). No trailing commas in type parameters in TypeScript. "none" - No trailing commas.
解決
- prettier插件版本回退到v2.8.8
"prettier":"v2.8.8"
- vue-loader配置prettify: false。
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
// vue loader在處理.vue模板時(shí)默認(rèn)不用prettier格式化
prettify: false,
},
},以上就是SyntaxError: /xx.vue: Unexpected token, expected “,“錯(cuò)誤解決的詳細(xì)內(nèi)容,更多關(guān)于SyntaxError vue 解決的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
vue-cookies使用方法與vue使用獲取cookie實(shí)現(xiàn)過程
本文主要介紹了 Vue 中使用 vue-cookies 庫的操作方法,包括安裝、引入、設(shè)置、獲取、刪除 cookies 等,并針對(duì)瀏覽器存在 cookie 前端卻獲取不到的問題進(jìn)行了分析,提出了解決方案2026-04-04
深度解析Vue3實(shí)現(xiàn)日歷組件的五大主流方案
在 Vue3 項(xiàng)目開發(fā)中,日歷組件是日程管理,預(yù)約系統(tǒng),數(shù)據(jù)可視化等場(chǎng)景的核心組件,本文將從易用性,擴(kuò)展性,性能三個(gè)維度,深入分析 5 款主流 Vue3 日歷組件,并提供選型建議,幫助開發(fā)者快速找到適配場(chǎng)景的最佳方案2026-04-04
vue實(shí)現(xiàn)圖片滾動(dòng)的示例代碼(類似走馬燈效果)
下面小編就為大家分享一篇vue實(shí)現(xiàn)圖片滾動(dòng)的示例代碼(類似走馬燈效果),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
Vue路由對(duì)象屬性 .meta $route.matched詳解
今天小編就為大家分享一篇Vue路由對(duì)象屬性 .meta $route.matched詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue使用echarts時(shí)created里拿到的數(shù)據(jù)無法渲染的解決
這篇文章主要介紹了vue使用echarts時(shí)created里拿到的數(shù)據(jù)無法渲染的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
Vue動(dòng)畫之第三方類庫實(shí)現(xiàn)動(dòng)畫方式
這篇文章主要介紹了Vue動(dòng)畫之第三方類庫實(shí)現(xiàn)動(dòng)畫方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04

