vscode+react+ESLint解决不引入组件,vscode不会报错的问题

解决不引入组件,vscode不会报错的问题

typescript 复制代码
routes.jsx       全部代码如下
export const routes = [
    {
        path:"/",
        element:<Home/>
    }
]

在项目根目录下新建个

eslint.config.js

加入下面的代码,要保证node_modules里安装了
eslint-plugin-react (主要是这个)

eslint-plugin-react-hooks

eslint-plugin-react-refresh

typescript 复制代码
import js from "@eslint/js";
import globals from "globals";
import reactPlugin from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";

export default [
  { ignores: ["dist", "build", "node_modules"] },
  {
    files: ["**/*.{js,jsx}"],
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser,
      parserOptions: {
        ecmaVersion: "latest",
        sourceType: "module",
        ecmaFeatures: { jsx: true },
      },
    },
    settings: { react: { version: "detect" } },
    plugins: {
      react: reactPlugin,
      "react-hooks": reactHooks,
      "react-refresh": reactRefresh,
    },
    rules: {
      ...js.configs.recommended.rules,
      ...reactPlugin.configs.recommended.rules, // ← 插件推荐里包含 jsx-no-undef 等
      ...reactHooks.configs.recommended.rules,
      "no-unused-vars": "off", // 关掉 ESLint 对未使用变量的默认规则(如果已开启的话)
      // 如果想手动写,也可以:
      // 'react/jsx-no-undef': 'error',
      // 'react/jsx-uses-vars': 'error',
      // 'react/jsx-uses-react': 'error',
      // 'no-undef': 'error',
    },
  },
];

然后安装插件ESLint

相关推荐
抱抱宝9 小时前
Agent-study项目教程(03):手写 Mini-ReAct Agent(不依赖框架)
javascript·人工智能·gpt·react.js·prompt·agent
2401_8582861113 小时前
VSCODE远程链接错误: 无法建立链接,过程试图写入的管道不存在的解决方法
ide·vscode·编辑器
像风一样自由202013 小时前
加强版VScode结合remote-ssh远程连接服务器开发指南
服务器·vscode·ssh
想要成为糕糕手14 小时前
🚀 在浏览器里跑 DeepSeek-R1?WebGPU 端侧推理实战(六)—— 完结篇:消息渲染与流式收尾
react.js·typescript·llm
一朵好运莲14 小时前
Turbo Console Log插件VSCode更改log快捷键教程
ide·vscode·编辑器
YIAN15 小时前
从 Hash 底层原理到 React Router v6 实战:我学会了什么?
前端·react.js·vue-router
YUS云生16 小时前
大模型学习·第46天:Agent智能体核心概念与ReAct框架
前端·学习·react.js
To_OC16 小时前
后端接口还没交付,前端如何独立把整套业务跑通
前端·react.js·全栈
程序员跑路18 小时前
Barrel Export、Jest、Babel 与依赖图
react.js
l1m0_18 小时前
告别反复修改Prompt:AI生成React应用并落地开发的实战复盘
前端·react.js·ui·ai·设计