SyntaxError:?/xx.vue:?Unexpected?token,?expected?“,“錯誤解決
錯誤
本地老工程vue2.7.x+webpack4在升級webpack5的時候遇啟動和打包報錯:
Syntax Error: SyntaxError: /xxxxx.vue Unexpected token, expected "," (1:8) > 1 | [object Promise] | ^ 2 | export { render, staticRenderFns }
最后才發(fā)現(xiàn)是prettier導致的。
推薦看看stackoverflow上面這個回答。Update Nodejs 14->18 — webpack have the same syntaxError: /.../xxx.vue: Unexpected token, expected "," (1:8) for ALL Vue 2 components in the project
導致原因
在prettier v3.0.0中,默認值從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模板時默認不用prettier格式化 prettify: false, }, },
以上就是SyntaxError: /xx.vue: Unexpected token, expected “,“錯誤解決的詳細內容,更多關于SyntaxError vue 解決的資料請關注腳本之家其它相關文章!
相關文章
vue雙向錨點實現(xiàn)過程簡易版(scrollIntoView)
這篇文章主要介紹了vue雙向錨點實現(xiàn)過程簡易版(scrollIntoView),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07vue.js中created()與activated()的個人使用解讀
這篇文章主要介紹了vue.js中created()與activated()的個人使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07vue-resource post數(shù)據(jù)時碰到Django csrf問題的解決
這篇文章主要介紹了vue-resource post數(shù)據(jù)時碰到Django csrf問題的解決,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03