在我的打字稿项目中,我使用的是eslint。下面的文件位于根目录中,并且我还有子文件夹PS C:\src\t> (Test-Connection -ComputerName localhost -Count 1).responsetime
0
PS C:\src\t> $PSVersionTable.PSVersion.ToString()
5.1.17763.1007
和/dist
。
eslintrc.js
/src
tsconfig.json
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json']
},
rules: {
strict: "error",
semi: ["error", "always"],
"no-cond-assign": ["error", "always"]
},
plugins: [
'@typescript-eslint'
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
};
顶部的单词{
"compilerOptions": {
"outDir": "dist",
"noImplicitAny": true,
"moduleResolution": "Node",
"resolveJsonModule": true,
"module": "ES2020",
"target": "ES2020",
"lib": ["ES2020"],
"allowJs": false,
"alwaysStrict":true
},
"include": [
"src"
]
}
用红线表示此错误
module
我该如何解决?
答案 0 :(得分:6)
先前的答案确实具有正确的链接,但是答案是将eslintrc.js更新为包括:ignorePatterns: ['.eslintrc.js']
答案 1 :(得分:1)
相同的错误,这对我有用: https://github.com/nestjs/nest/issues/4900#issuecomment-669743374 https://github.com/nestjs/nest/issues/4900#issuecomment-707330674
看起来配置文件必须命名为.eslintrc并使用json格式而不是.eslintrc.js,并且parserOptions.createDefaultProgram必须设置为true
答案 2 :(得分:1)
烦人的错误基本上是说文件eslintrc.js
本身是两者:
所以,ESLint 不知道该怎么做并且吓坏了!
请注意,虽然此文件不包含您的代码,但您应该决定是否要对这个文件进行 linted(例如,制表符与空格,或双引号与单引号)。
您可以省略上述冲突情况中的 (1) 或 (2)。
更简单。只需将文件名(例如 .eslintrc.js
)添加到 .eslintignore
。
您还可以查看 case 1.3 of my answer, here 以了解不同的实现方式。
Typescript-ESLint 通过 tsconfig.json
从 parserOptions > project
获取要包含的文件列表。
因此,您可以将文件添加到现有的 tsconfig.json
(解决方案 2.1)或创建辅助 tsconfig.eslint.json
以包含这样的文件,您希望通过 typescript-eslint 对其进行检查,但是不一定由 Typescript 编译器处理。
解决方案 2.1:将其添加到现有的 tsconfig.json
// in tsconfig.json ...
"include": [
".eslintrc.js",
// ...
]
解决方案 2.2:将其添加到单独的 tsconfig.eslint.json
文件
使用以下内容创建一个名为 tsconfig.eslint.json
的文件:
// new file: tsconfig.eslint.json
{
"include": [
".eslintrc.js"
]
}
然后将其注入到 eslintrc.js
的 parserOptions
> project
(是的,project
接受字符串和字符串数组):
// in eslintrc.js ...
parserOptions: {
project: [
resolve(__dirname, './tsconfig.json'),
resolve(__dirname, './tsconfig.eslint.json'),
],
}
附注。 This answer 非常相似,我会对此表示感谢。