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 报错应该如何解决?
免责声明:本站来源的信息均由网友自主投稿和发布、编辑整理上传,或转载于第三方平台,对此类作品本站仅提供交流平台,不为其版权负责。本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本站联系,我们将及时更正、删除,谢谢。联系邮箱:elon368@sina.com

