[英]How to resolve "Definition for rule '@typescript-eslint/rule-name' was not found"
I'm trying to add TypeScript compilation to an existing Javascript project.我正在尝试将 TypeScript 编译添加到现有的 Javascript 项目中。
AFAIK this is supposed to be possible (even easy), and you can incrementally spread TS through the codebase.据我所知,这应该是可能的(甚至很容易),并且您可以通过代码库逐步传播 TS。 Unfortunately this isn't what I'm seeing - after adding typescript and trying to start the project, I get this error for every single file in the project:
不幸的是,这不是我所看到的——在添加 typescript 并尝试启动项目后,项目中的每个文件都会出现此错误:
Definition for rule '@typescript-eslint/rule-name' was not found
There is no instance of the string rule-name
anywhere in my source code.在我的源代码中的任何地方都没有字符串
rule-name
的实例。
This is my tsconfig.json
:这是我的
tsconfig.json
:
{
"compilerOptions": {
"baseUrl": "src",
"noImplicitAny": false,
"sourceMap": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"esModuleInterop": true,
"jsx": "react",
"skipLibCheck": true
},
"include": [
"src",
"types"
],
"exclude": [
"node_modules",
"build"
]
}
I have tried adding "checkJs": false
to the config and restarting but that doesn't change anything.我尝试将
"checkJs": false
添加到配置中并重新启动,但这并没有改变任何东西。
I haven't been able to track down anything online about this "rule-name" problem.我无法在网上找到有关此“规则名称”问题的任何信息。 It really looks like this is a placeholder text of some sort, but I can't find the source.
看起来这确实是某种占位符文本,但我找不到来源。
Can anybody suggest anything that might help me get this project to build?任何人都可以提出任何可以帮助我构建这个项目的建议吗?
The error that you have is coming from ESLint and means that you have a rule in your .eslintrc
which doesn't exist in any of your plugins.您遇到的错误来自 ESLint,这意味着您的
.eslintrc
有一条规则,该规则在您的任何插件中都不存在。 This could have happened if you followed the usage guide for @typescript-eslint/eslint-plugin
but didn't replace the placeholder rule-name
with an actual rule name as seen here https://www.npmjs.com/package/@typescript-eslint/eslint-plugin如果您遵循
@typescript-eslint/eslint-plugin
的使用指南,但没有将占位符rule-name
替换为实际规则名称,则可能会发生这种情况,如此处所示https://www.npmjs.com/package/@打字稿-eslint/eslint-plugin
For those who do not want to just disable ESLint but make it work, running npm update
could resolve the issue.对于那些不想仅禁用 ESLint 但使其工作的人,运行
npm update
可以解决问题。 In my case updating just @typescript-eslint/parser
and @typescript-eslint/eslint-plugin
was not enough but after npm update
warnings dissapeared and ESLint was up and running.在我的情况下,仅更新
@typescript-eslint/parser
和@typescript-eslint/eslint-plugin
是不够的,但是在npm update
警告消失并且 ESLint 启动并运行之后。
Also worth to keep in mind this higlight from package authors:同样值得记住的是包作者的这一亮点:
It is important that you use the same version number for @typescript-eslint/parser and @typescript-eslint/eslint-plugin.
@typescript-eslint/parser 和 @typescript-eslint/eslint-plugin 使用相同的版本号很重要。
If you're using react-app-rewired
and customize-cra
, you need to make sure you use disableEsLint
from the latter;如果您使用
react-app-rewired
和disableEsLint
customize-cra
,则需要确保使用后者的disableEsLint
; otherwise linting errors become typescript errors and prevent compilation.否则,linting 错误会变成打字稿错误并阻止编译。
This is because the rule is not declared in your eslint.json file Add the following line to your RULES in esling.json file这是因为该规则未在您的 eslint.json 文件中声明 将以下行添加到 esling.json 文件中的 RULES
"@typescript-eslint/object-curly-spacing" : "off" “@typescript-eslint/object-curly-spacing”:“关闭”
Refer the image below to know more参考下图了解更多
Refer this image to add the rule to eslint.json file参考此图片将规则添加到 eslint.json 文件
For me, it was enough to add plugin:@typescript-eslint/recommended in the.eslintrc file.对我来说,在 .eslintrc 文件中添加 plugin:@typescript-eslint/recommended 就足够了。
"extends": [
...<otherExtentions>...
"plugin:@typescript-eslint/recommended"
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.