[英]Why is create-react-app giving typescript error when trying to eslint (though no typescript files)?
I am getting this error when i do eslint.
当我做
eslint.
Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.yml »
eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
Because there are TypeScript files - although ESLint excludes node_modules/
from linting by default, CRA's override (in order to load appropriate plugins for any TypeScript files, this is why you see eslint-config-react-app#overrides[0]
in the output) does include the content of node_modules/
(see eg this issue ).因为有TypeScript 文件 - 尽管 ESLint 默认排除
node_modules/
从 linting 中排除,但 CRA 的覆盖(为了为任何 TypeScript 文件加载适当的插件,这就是为什么你在输出中看到eslint-config-react-app#overrides[0]
) 确实包括node_modules/
的内容(参见例如这个问题)。
You can install TypeScript, but if you don't intend to use any TypeScript files in your own source you can be more specific about what you want to lint instead.您可以安装 TypeScript,但如果您不打算在您自己的源代码中使用任何 TypeScript 文件,您可以更具体地说明您想要 lint 的内容。 Either:
任何一个:
Change the script in package.json
to only lint the source directory:将
package.json
中的脚本更改为仅对源目录进行 lint:
"lint": "eslint src/"
Create a .eslintignore
(or another file, if you set the right --ignore-path
) file containing:创建一个
.eslintignore
(或另一个文件,如果您设置了正确的--ignore-path
)文件,其中包含:
node_modules/
Add to the ESLint configuration object in package.json
(or pass it as an --ignore-pattern
):在 package.json 中添加 ESLint 配置
package.json
(或将其作为--ignore-pattern
传递):
"eslintConfig": { "extends": "react-app", "ignorePatterns": [ "node_modules/" ] }
The latter two options are from the documentation on configuration .后两个选项来自配置文档。
npm install --save-dev typescript
Then eslint.
然后
eslint.
will work as intended and can use the .eslintrc.yml
file.将按预期工作并且可以使用
.eslintrc.yml
文件。
btw I had also just installed顺便说一句,我也刚刚安装
npm install -save-save eslint-plugin-typescript
in case you are doing this as you may need that too.如果您正在这样做,您可能也需要这样做。
btw do NOT install eslint with npm install eslint... as it may mess up due to the fact that... crewate-react-app already has it (but a lower version).顺便说一句,不要使用 npm 安装 eslint 安装 eslint... 因为它可能会因为...Crewate-react-app 已经拥有它(但版本较低)而搞砸。 so just add your eslintrc.yml file and it will work (be applied in the editor, and with this fix, at the command line as neeeded).
所以只需添加您的 eslintrc.yml 文件,它就可以工作(在编辑器中应用,并根据需要在命令行中使用此修复程序)。
example output:例如 output:
.../src/components/SignUp/index.js
1:41 error Missing semicolon semi
7:26 error Unnecessary parentheses around expression no-extra-parens
15:2 error Missing semicolon semi
32:13 error 'username' is assigned a value but never used no-unused-vars
47:63 error Missing semicolon semi
95:26 error Unnecessary parentheses around expression no-extra-parens
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.