Closed pany-ang closed 1 year ago
如果依赖的 ts 版本小于 5,那么出现这个告警的原因应该是最新版 vscode,测试后发现好像 vscode 1.74 以及更早的版本不会出现该告警(这种情况下,你几乎只能忍着这个警告不管,其他措施会导致 build 报错,或者降低你的 vscode 版本来临时解决该报错)
如果依赖的 ts 版本大于 5,那么你可以选择将 moduleResolution 配置为 bundler,但是这样的话,其他依赖(比如 Element Plus)可能就会疯狂报错(等待官方修复这个问题中...)。你也可以选择 “// @ts-expect-error” 来忽略这个错误,忽略后能正常 build
依赖的 ts 小于 5,并且又是最新版 vscode 时最难受,几乎处理不了这个报错(可以降低 vscode 版本,也可以手动切换 vscode 右下角采用的 ts 版本为工作区版本)
所以总结一下,如果依赖的 ts 小于 5,那么就不要去管它(让它一直报错吧,想解决就参考第 3 点),别的 issues 里面的别人给的方法,几乎都会导致 build 出错。如果 ts 大于 5,那么就暂时用 “// @ts-expect-error” 来忽略这个错误,这样能正常 build
If the dependent TS version is less than 5, then the reason for this alarm should be the latest version of VSCODE, after testing, it seems that VSCODE 1.74 and earlier versions will not appear this alarm (in this case, you can almost endure this warning, other measures will cause build errors, or reduce your VSCODE version to solve the error temporarily)
If the dependent ts version is greater than 5, then you can choose to configure moduleResolution as a bundler, but in this case, other dependencies (such as Element Plus) may report crazy errors (waiting for the official fix for this problem...). )。 You can also select "// @ts-expect-error" to ignore this error, and it will build normally after ignoring it
The dependent TS is less than 5, and it is the most uncomfortable when the latest version of VSCODE, and it is almost impossible to handle this error (you can reduce the VSCODE version, or manually switch the TS version used in the lower right corner of VSCODE to the workspace version)
So to sum up, if the dependent ts is less than 5, then don't care about it (let it keep reporting errors, and if you want to solve it, refer to point 3), other issues in the methods given by others, almost all will cause build errors. If ts is greater than 5, then temporarily use "// @ts-expect-error" to ignore this error, so that it can build normally
如果出现类似报错:Cannot find module 'xxx/vite' or its corresponding type declarations
是因为 v3-admin-vite v3.3.4 及其以下版本依赖的 ts 版本小于 5(马上发版的 v3.4.0 依赖的 ts 大于 5),但是最新版 vscode 内置的 ts 版本大于 5,这时候 vscode 默认是使用的内置 ts 版本,你可以手动在右下角切换:
这样确保项目依赖的 ts 版本和实际使用的一致,就没问题了