Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译后出现 Uncaught SyntaxError: Unexpected token '...' #255

Closed
cnhuye opened this issue Aug 5, 2022 · 5 comments
Closed

编译后出现 Uncaught SyntaxError: Unexpected token '...' #255

cnhuye opened this issue Aug 5, 2022 · 5 comments

Comments

@cnhuye
Copy link

cnhuye commented Aug 5, 2022

esbuild 中配置了 pure, 移除了所有 console.log 后, 会出现错误信息:

Uncaught SyntaxError: Unexpected token '...'

找到原因,是因为这个文件
https://github.com/mirari/v-viewer/blob/v3/src/directive.ts
98行 log 方法里 console.log(...args), 被 esbuild 去除了 console.log 后, 代码变成了:

debug && ...args

有什么办法能解决这个问题呢?

@mirari
Copy link
Owner

mirari commented Aug 5, 2022

我认为这其实算是esbuild的pure组件bug,需要看下它的配置项是否允许例外,将node_modules排除

@mirari
Copy link
Owner

mirari commented Aug 5, 2022

我看到esbuild的issue有讨论类似问题,不过没有提到node_modules内部出现此类问题的情况,我空的时候去问下。你也可以找找是否有关闭pure配置以外的其他途径。
evanw/esbuild#1879

@mirari
Copy link
Owner

mirari commented Aug 8, 2022

能提供下你的框架环境吗?我需要尝试复现这个问题。

@cnhuye
Copy link
Author

cnhuye commented Aug 8, 2022

https://github.com/vbenjs/vue-vben-admin
用的这个框架.
他的 vite 配置里加了 esbuild.pure , 然后出现了这个问题。

如果用一个最小的 vue3+vite, 配置上 esbuild.pure 应该也可以复现。

@mirari
Copy link
Owner

mirari commented Aug 8, 2022

已提交issue,esbuild反馈是bug,之后会修复。
目前可以暂时关闭pure配置项,或者使用drop配置项来完全移除console.log,代价是console.error等方法也会移除。

drop: ['console', 'debugger'],

@mirari mirari closed this as completed May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants