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" 这种引入???
转载请注明:可思数据 » vite 自动引入,eslint 报错应该如何解决?