当前位置: 首页 > news >正文

react项目因eslint检测未通过而Failed to compile编译失败

环境

  • node v16.20.2
  • react 18.3.1
  • react-scripts 4.0.3

.eslintrc.json 配置:

{"env": {"browser": true,"es6": true,"node": true},"settings": {"react": {"pragma": "React","version": "detect"}},"plugins": ["react", "react-hooks", "@typescript-eslint"],"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:@typescript-eslint/recommended"],"parser": "@typescript-eslint/parser","rules": {"no-caller": 2,"no-undef": 2,"no-unused-vars": 2,"no-use-before-define": 0,"object-curly-spacing": ["error", "always"],"strict": 0,"semi": 2,"no-loop-func": 0,"no-multi-spaces": "error","keyword-spacing": ["error",{"before": true,"after": true}],"quotes": ["error","single",{"allowTemplateLiterals": true}],"indent": ["error",2,{"SwitchCase": 1}],"no-console": ["error"],"camelcase": ["error",{"properties": "always","ignoreDestructuring": false}],"@typescript-eslint/explicit-module-boundary-types": "off","react-hooks/rules-of-hooks": "error","react-hooks/exhaustive-deps": "error"},"ignorePatterns": ["dist/**/*"],"overrides": [{"files": ["tests/**/*"],"env": {"jest": true}}]
}

报错信息

Failed to compile.src/TreeView.jsxLine 181:10:  'test' is assigned a value but never used     no-unused-varsLine 181:16:  'setTest' is assigned a value but never used  no-unused-varsSearch for the keywords to learn more about each error.

开发过程中,因为eslint问题,无法很好debug调试程序,影响效率。

解决方式

开发过程仅提示即可,避免eslint造成的编译失败;只需保证build构建环节eslint问题报错即可。

在本地开发环境 .env.development 文件中配置 ESLINT_NO_DEV_ERRORS=true

配置完后,出现的就是 eslint 相关 warnings.

Compiled with warnings.src/TreeView.jsxLine 181:10:  'test' is assigned a value but never used     @typescript-eslint/no-unused-varsLine 181:16:  'setTest' is assigned a value but never used  @typescript-eslint/no-unused-varssrc/TreeView.jsxLine 181:10:  'test' is assigned a value but never used     no-unused-varsLine 181:16:  'setTest' is assigned a value but never used  no-unused-varsSearch for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

参考:https://create-react-app.dev/docs/advanced-configuration/


http://www.mrgr.cn/news/58718.html

相关文章:

  • Matlab的安装和破解
  • self-supervised learning(BERT和GPT)
  • 基础巩固:
  • django5入门【02】创建新的django程序
  • JavaSE——IO流7:其他流
  • 如何将rust日志输出到android终端
  • Go操作Redis
  • 智创 AI 新视界 -- 探秘 AIGC 中的生成对抗网络(GAN)应用
  • Java项目实战II基于微信小程序的智慧旅游平台(开发文档+数据库+源码)
  • 算法的学习笔记—平衡二叉树(牛客JZ79)
  • WPF+MVVM案例实战(四)- 自定义GroupBox边框样式实现
  • 单片机开发环境搭建
  • 快速排序(hoare版本)
  • 动态规划一>简单多状态系列
  • 在WebStorm遇到Error: error:0308010C:digital envelope routines::unsupported报错时的解决方案
  • It行业重点知识点详解操作系统学习方法
  • 什么是DSSA?
  • mysql建表
  • C#从零开始学习(GameObject实例)(unity Lab3)
  • C# LINQ 基础与应用
  • 判断特定时间点开仓的函数(编程技巧)
  • 如何提高游戏的游戏性
  • Flutter之build 方法详解
  • 创建插件 DLL 项目
  • Idea基于JRbel实现项目热部署修改Java、Xml文件无需重启项目
  • 【南方科技大学】CS315 Computer Security 【Lab6 IoT Security and Wireless Exploitation】