首页 > 解决方案 > VSCode eslint 不拾取 tsconfig 路径

问题描述

VSCode linting 似乎不尊重我在 tsconfig.json 文件中定义的路径。

从 tsconfig.json 中定义的“别名”导入任何内容时,出现以下错误。

在此处输入图像描述

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "./dist/",
    "module": "esNext",
    "strictNullChecks": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "jsx": "preserve",
    "skipLibCheck": true,
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "declaration": true,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "target": "es5",
    "lib": ["es5", "es6", "es7", "es2017", "dom"],
    "types": ["react", "jest", "node"],
    "baseUrl": ".",
    "paths": {
      "~*": ["./src/*"],
      "common/*": ["src/common/*"],
      "test/*": ["test/*"],
      "test-utils": ["test/test-utils.tsx"],
      "static/*": ["static/*"],
      "storybook/*": [".storybook/*"]
    },
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "resolveJsonModule": true,
    "isolatedModules": true
  },
  "include": ["__root/src/**/*", "src/typings.d.ts", "./@types", ".storybook/decorators/**/*"],
  "exclude": ["./node_modules", "dist"]
}

.eslintrc

{
  "extends": ["react-app"],
  "plugins": ["prettier"],
  "parser": "@typescript-eslint/parser",
  "rules": {
    "prettier/prettier": "error"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

包版本:

"@typescript-eslint/parser": "^4.3.0",
"babel-eslint": "10.1.0",
"eslint": "7.10.0",
"eslint-config-react-app": "^5.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "6.3.1",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-react": "7.21.2",

.prettierrc

{
    "printWidth": 100,
    "tabWidth": 2,
    "useTabs": false,
    "semi": true,
    "singleQuote": true,
    "trailingComma": "none",
    "bracketSpacing": true,
    "jsxBracketSameLine": false,
    "arrowParens": "avoid"
}

我一直在寻找一个我几个小时都没有尝试过的解决方案,但我没有找到任何与本地模块和 tsconfig 路径别名特别相关的东西。

(代码工作和构建都很好,这只是我在 VScode 中看到的一个 linting 问题)

tslint在 VSCode 中安装了该软件包。我试过删除它并用它替换它,eslint但这没有任何区别。

标签: typescriptvisual-studio-codeeslinttsconfig

解决方案


推荐阅读