make sure both eslint and eslint-config-next are installed
Answer from Mohammad on Stack Overflowmake sure both eslint and eslint-config-next are installed
This happened to me because I somehow ended up with an extra .eslintrc.json file outside of my Next project directory which was getting picked up by my IDE (WebStorm)
For example:
parent-folder
.eslintrc.json <-- Delete this
next-folder
pages
package.json
.eslintrc.json <-- This one is correct
tsconfig.json
README.md
» npm install @next/eslint-plugin-next
Try this
import pluginNext from '@next/eslint-plugin-next'
export default defineConfig([
{
plugins: {
'@next/next': pluginNext
},
},
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
...pluginNext.configs.recommended.rules
}
}
])
This works for me (I tested with next 15.0.3 / eslint 9.14 / eslint-config-next 15.0.3)
eslint.config.mjs
import pluginNext from '@next/eslint-plugin-next';
import parser from '@typescript-eslint/parser'; // optional
export default [
{
name: 'ESLint Config - nextjs',
languageOptions: {
parser, // optional
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
'@next/next': pluginNext,
},
files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'],
rules: {
...pluginNext.configs.recommended.rules,
...pluginNext.configs['core-web-vitals'].rules,
},
},
];
I've been struggling to find out why this happens for the last hour! These issues exist in both VS Code and Webstorm:
initialize a project with npx create-next-app, eslint, typescript and all -> the ESLint plugins for both VSCode and Webstorm works fine, shows warnings etc.
initialize a projext with npx create-next-app --use-pnpm, eslint, ts -> the ESlint plugins for both misbehave:
VSCode -> throws no warnings no matter what .tsx file I open and change stuff
Webstorm -> throws errors like "Error: Failed to load plugin 'react-hooks' declared in ' » eslint-config-next/core-web-vitals" and the ""fix"" I've found atm is to explicitly install `@next/eslint-plugin-next` as a dev dependency
Why does pnpm not love me? Is it pnpm's fault, create-next-app's fault for how it handles pnpm, or something else?
I'm wondering if anyone is willing to share their eslint.config.mjs file, for the latest Next 15.5? There's so many options and I wonder if there's some industry standards that are good to go for most projects
This is the one I'm using right now (with GPT's help)
// eslint.config.mjs
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import unusedImports from "eslint-plugin-unused-imports";
const compat = new FlatCompat({
baseDirectory: import.meta.dirname,
recommendedConfig: js.configs.recommended,
});
export default [
{
ignores: ["**/node_modules/**", ".next/**", "dist/**", "coverage/**", "**/*.min.js"],
},
...compat.config({
extends: ["next/core-web-vitals", "next/typescript", "prettier"],
}),
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: {
"unused-imports": unusedImports,
},
rules: {
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
"type",
],
alphabetize: { order: "asc", caseInsensitive: true },
},
],
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
{ varsIgnorePattern: "^_", argsIgnorePattern: "^_" },
],
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-explicit-any": "off",
},
},
];