Vue Oxlint 2024 07 03

Vue Oxlint 2024 07 03

Posted by     "Brian" on Wednesday, July 3, 2024

如果在我们的项目中使用了 eslint 或者 oxlint 后 如果配置了 @ 加载资源,然后使用 import 语法导入相应的文件时遇到飘红的错误。现象如下, '@/store/modules/baidu'是带有红色下划线的:

import { useBaiDuAiStoreWithOut } from '@/store/modules/baidu'
                                        ~~~~~~~~~~~~~~~~~~~~~~

TS错误信息为 :

TS2307: Cannot find module '@/path/some/module' or its corresponding type declarations.

这时候只需要在 tsconfig.app.json 文件中的 compilerOptions 字段中增加以下内容就可以解决:

"baseUrl": "./",
"paths": {
  "@/*": ["src/*"]
}

ts 错误码 TS7016,

TS7016: Could not find a declaration file for module 'vite-plugin-oxlint'.

增加 如下代码即可解决

// @ts-ignore

prettier 代码格式化

https://www.prettier.cn/docs/configuration.html