typescript - 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
但这没有任何区别。
解决方案
推荐阅读
- ruby-on-rails - link_to 助手崩溃
- c# - ASP .Net Core 3.0 - Log4Net MS SQL Server Appender 不工作
- c++ - 如何强制,值成为左值参考?
- java - 完全相同的视图可以从 XML 正确呈现,但不能从 Java 代码中正确呈现
- c# - 订阅包含另一个 IObservableCollection 的 IObservableCollection (SourceList)
- php - WP Query,最新帖子不显示
- python - 传递有序字符串数字变量时 seaborn 的 PairGrid 函数中的错误?
- sql - 有没有更有效的方法在这个特定的上下文中编写我的过滤器?
- javascript - 带有ajax的表单onsubmit总是在第一次加载页面时提交两次
- eclipse - 基数是如何从 ecore 元模型写在 XText 上的?