NextJS 15 下正确的 eslint 配置

问题描述 投票:0回答:1

我刚刚升级到 NextJS 15.0.1、eslint 9.13.0、@next/eslint-plugin-next 15.0.1

我不知道如何在构建过程中消除此错误:

The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config

提供的 URL 中的说明适用于旧的 eslintrc 配置格式。

有什么建议吗?

我的eslint.config.mjs如下:

import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";

export default [
  {files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
  {languageOptions: {globals: {...globals.browser, ...globals.node}}},
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  pluginReact.configs.flat.recommended,
  {
    rules: {
      "@typescript-eslint/no-unused-vars": "off",
      "react/prop-types": "off",
      "react/react-in-jsx-scope": "off",
      "@typescript-eslint/no-empty-object-type": "off", // remove
      "no-prototype-builtins": "off", // explore
      "no-unused-vars": "warn",
      "no-undef": "warn",
    },
  },
  {
    ignores: ["src/tools/"],
  },
];

我只是想摆脱警告。

next.js eslint config
1个回答
0
投票

试试这个

import pluginNext from '@next/eslint-plugin-next'

export default defineConfig([
  {
    plugins: {
      '@next/next': pluginNext
    },
  },
  {
    files: ['**/*.ts', '**/*.tsx'],
    rules: {
      ...pluginNext.configs.recommended.rules
    }
  }
])
© www.soinside.com 2019 - 2024. All rights reserved.