DEV Community

Cui Mingda
Cui Mingda

Posted on

1 1

How to fix Error Failed to load typescript eslint parser in eslint-config-react-app

用create-react-app创建的项目,直接执行yarn eslint .,会抛出以下错误:

Error: Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
Enter fullscreen mode Exit fullscreen mode

原因是校验根目录下所有文件,自然也包括node_modules目录的文件,里面有typescript代码,于是就用typescript parser解析,但项目创建的时候又没有创建成typescript项目,于是缺少组件,自然会报错。

解决办法就是只校验src目录就好了。

yarn eslint "src/**/*.js"
yarn eslint --ext .jsx --ext .js src/
Enter fullscreen mode Exit fullscreen mode

References

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay