我在执行 eslint 时遇到此错误。
Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.yml »
eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
最佳答案
因为有 TypeScript 文件——尽管 ESLint 默认将 node_modules/
从 linting 中排除,CRA 的 override (为了为任何 TypeScript 文件加载适当的插件,这就是为什么您在输出中看到 eslint-config-react-app#overrides[0]
的原因)确实包含 node_modules/的内容
(参见例如 this issue)。
您可以安装 TypeScript,但如果您不打算在您自己的源代码中使用任何 TypeScript 文件,您可以更具体地说明您想要 lint 的内容。要么:
将
package.json
中的脚本更改为仅 lint 源目录:"lint": "eslint src/"
创建一个
.eslintignore
(或另一个文件,如果您设置了正确的--ignore-path
)文件包含:node_modules/
添加到
package.json
中的 ESLint 配置对象(或将其作为--ignore-pattern
传递):"eslintConfig": { "extends": "react-app", "ignorePatterns": [ "node_modules/" ] }
后两个选项来自the documentation on configuration .
关于reactjs - 为什么 create-react-app 在尝试 eslint 时会给出 typescript 错误(尽管没有 typescript 文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62921635/