vue.js

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript类库 > vue.js > SyntaxError vue 解决

SyntaxError: /xx.vue: Unexpected token, expected “,“错误解决

作者:天渺工作室

这篇文章主要为大家介绍了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 }

最后才发现是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"

{
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          // vue loader在处理.vue模板时默认不用prettier格式化
          prettify: false,
        },
   },

以上就是SyntaxError: /xx.vue: Unexpected token, expected “,“错误解决的详细内容,更多关于SyntaxError vue 解决的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:
阅读全文