SyntaxError: /xxxx.vue: Unexpected token, expected “,“,[object Promise]export { render, staticRende}

2 篇文章 0 订阅
本地老工程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.

vue-loader涉及prettier配置项

image.png

解决方法1

prettier插件版本回退到v2.8.8

"prettier":"v2.8.8"
解决方法2

vue-loader配置prettify: false。

   {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          // vue loader在处理.vue模板时编译后不用prettier格式化
          prettify: false,
        },
   },
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值