我在 Vite.js 上使用 Vue 3 和 Eslint + Airbnb 配置。Airbnb 配置有一个规则eslint(import/no-unresolved),这很好,但 Eslint 不知道如何解析别名路径。
我想对路径 \xe2\x80\x94 使用别名,例如:\nimport TableComponent from \'@/components/table/TableComponent.vue\'\xcb\x99
环境是纯 JavaScript 的。
\n我设法设置了我的vite.config.js应用程序可以解析这样的路径:
import path from \'path\';\nimport { defineConfig } from \'vite\';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [vue()],\n resolve: {\n alias: [{\n find: "@", replacement: path.resolve(__dirname, \'src\')\n },],\n },\n});\nRun Code Online (Sandbox Code Playgroud)\nVue 应用程序的工作方式如下并正确解析导入路径,但 Eslint 不断报告错误:Unable to resolve path to module eslint(import/no-unresolved)
我如何以及在哪里可以告诉 Eslint 如何解析别名?
\n我已经尝试过:\ninstall eslint-plugin-import eslint-import-resolver-alias --save-dev
我的 jsconfig.json 文件报告了一个问题:
File 'c:/.../node_modules/source-map/source-map' not found.
The file is in the program because:
Root file specified for compilation
Run Code Online (Sandbox Code Playgroud)
它总是报告两次,并指向{文件中的第一个。
这是我的jsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
}
},
"include": [
"src/**/*"
],
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
当我重新加载 VSCode 时,它消失了几分钟,然后在使用 VSCode 时重新出现。