zh-lx / code-inspector

Click the dom on the page, it will open your IDE and position the cursor to the source code location of the dom.
https://inspector.fe-dev.cn
MIT License
1.68k stars 124 forks source link

和 autoImport vitest 一同使用报错 #103

Closed liaolongdong closed 8 months ago

liaolongdong commented 8 months ago

大佬帮忙看一下,vite+vue3+vitest项目引入报错vendor-vi.dd6706cb.js:3226 Uncaught Error: Vitest failed to access its internal state. 把CodeInspectorPlugin注释掉,这个错误就没了

image image
zh-lx commented 8 months ago

请问方便提供一个仓库进行复现吗

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年02月01日 23:36 | | 收件人 | @.> | | 抄送至 | @.***> | | 主题 | [zh-lx/code-inspector] vite+vue3+vitest项目引入报错vendor-vi.dd6706cb.js:3226 Uncaught Error: Vitest failed to access its internal state. (Issue #103) |

大佬帮忙看一下,vite+vue3+vitest项目引入报错vendor-vi.dd6706cb.js:3226 Uncaught Error: Vitest failed to access its internal state. 把CodeInspectorPlugin注释掉,这个错误就没了 image.png (view on web)

image.png (view on web)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

liaolongdong commented 8 months ago

https://github.com/liaolongdong/vue3-ts-vite

zh-lx commented 8 months ago

感谢,我拉下来排查下

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年02月01日 23:47 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [zh-lx/code-inspector] vite+vue3+vitest项目引入报错vendor-vi.dd6706cb.js:3226 Uncaught Error: Vitest failed to access its internal state. (Issue #103) |

https://github.com/liaolongdong/vue3-ts-vite

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

zh-lx commented 8 months ago

经排查是因为插件打包后的客户端注入代码经过压缩和混淆后,混淆后的变量有的名为 it,所以 autoImport 插件误判了应该引入 vitest 中的 it 函数,从而导致报错。 我针对这个问题优化了下 vite 中的注入逻辑并发布了 0.6.4 版本,经测试 0.6.4 版本不再有报错,可以安装 0.6.4 版本使用。(但是感觉你 autoImport 的包太多了,这样写项目容易有变量命名冲突风险,建议项目最好也优化下)