vite自动引入,eslint报错应该如何解决?

LINK333 发布于 11/14 15:38
阅读 129
收藏 0

鸿蒙原生应用开发者激励计划发布!最高获百万现金!点击立即参与

eslint版本 9.9.0
vite版本 5.4.1

在vite中,配置了自动引入,但是eslint还是会报错ESLint: 'useState' is not defined.(no-undef),eslint应该怎么配置,求大佬告知???

// vite.config.js
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import AutoImport from "unplugin-auto-import/vite"


// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        react(),
        AutoImport({
            eslintrc: {
                enabled: false,
                filepath: "./.eslintrc-auto-import.json" //此文件为重新启动项目生成的文件
            },
            dts: "./auto-imports.d.ts",//此文件配置保存后系统自动生成
            imports: ["react", "react-router"] //此处可填写需要自动引入的库
        })
    ]
})


// eslint 
export default [
    {ignores: ["dist"]},
    {
        files: ["**/*.{js,jsx}"],
        languageOptions: {
            ecmaVersion: 2020,
            globals: globals.browser,
            parserOptions: {
                ecmaVersion: "latest",
                ecmaFeatures: {jsx: true},
                sourceType: "module"
            }
        },
        settings: {react: {version: "18.3"}},
        plugins: {
            react,
            "react-hooks": reactHooks,
            "react-refresh": reactRefresh
        },
        rules: {
            ...js.configs.recommended.rules,
            ...react.configs.recommended.rules,
            ...react.configs["jsx-runtime"].rules,
            ...reactHooks.configs.recommended.rules,
            "react/jsx-no-target-blank": "off",
            "react-refresh/only-export-components": [
                "warn",
                {allowConstantExport: true}
            ]
        }
    }
]

希望可以不用没有都写import { useState } from "react"这种引入???

加载中
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部