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

相关推荐
指针不南10 分钟前
Visual Studio 2022 / VS2022 激活码
ide·visual studio
Villiam_AY33 分钟前
从后端到react框架
前端·react.js·前端框架
゜ eVer ㄨ1 小时前
React学习第三天——生命周期
前端·学习·react.js
aesthetician2 小时前
@tanstack/react-query:React 服务器状态管理与数据同步解决方案
服务器·前端·react.js
举焰3 小时前
VSCode+MSVC+Qmake环境搭建笔记
c++·ide·笔记·vscode·msvc·qt5·qmake
智界工具库5 小时前
《IDEA 2025 长效使用指南:2099 年有效期配置实战之JetBrains全家桶有效》
java·ide·intellij-idea
Morpheon5 小时前
在 macOS Sequoia 中使用 Automator 添加 Finder 扩展:以“用 Cursor IDE 打开文件夹”为例
ide·macos
小关会打代码5 小时前
关于Pycharm中在运行出现语法错误:Non-UTF-8 code starting with
ide·python·pycharm
太空1号12 小时前
SystemVerilog小白入门1, iverilog+VScode
vscode
^Lim12 小时前
vscode连接ubuntu18报Gilbc2.28错
ide·vscode·编辑器