admin管理员组文章数量:1336711
Typescript project using eslint.config.mjs
. After upgrading to NextJS, started to see this warning message:
The Next.js plugin was not detected in your ESLint configuration. See
Changed eslint.config.mjs
to include the rules and the plugin. Following this post's suggestion: Proper eslint configuration under NextJS 15
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginNext from "@next/eslint-plugin-next";
export default tseslint.config({
files: ["src/**/*.ts", "src/**/*.tsx"],
ignores: ["src/__generated__/**/*"],
plugins: {
'@next/next': eslintPluginNext, // adding plugin
},
extends: [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
...eslintPluginNext.configs.recommended.rules, // importing the rules
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true
}
],
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
allowBoolean: true,
}
],
}
});
There is no other lint config files e.g. .eslintrc.json etc.
dev deps:
"@biomejs/biome": "^1.9.4",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/fragment-matcher": "^5.0.2",
"@graphql-codegen/typescript-operations": "^4.3.1",
"@graphql-codegen/typescript-react-apollo": "^4.3.2",
"@swc/core": "^1.9.2",
"@swc/helpers": "^0.5.15",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"dotenv": "^16.4.5",
"eslint": "^9.15.0",
"eslint-config-next": "^15.0.3",
"graphql": "^16.9.0",
"jest": "^29.7.0",
"postcss": "^8.4.49",
"shadcn": "^2.1.6",
"tailwindcss": "^3.4.15",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.14.0"
Is this a false positive ? This warning was not previously there in Next 14
Typescript project using eslint.config.mjs
. After upgrading to NextJS, started to see this warning message:
The Next.js plugin was not detected in your ESLint configuration. See https://nextjs./docs/app/building-your-application/configuring/eslint#migrating-existing-config
Changed eslint.config.mjs
to include the rules and the plugin. Following this post's suggestion: Proper eslint configuration under NextJS 15
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginNext from "@next/eslint-plugin-next";
export default tseslint.config({
files: ["src/**/*.ts", "src/**/*.tsx"],
ignores: ["src/__generated__/**/*"],
plugins: {
'@next/next': eslintPluginNext, // adding plugin
},
extends: [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
...eslintPluginNext.configs.recommended.rules, // importing the rules
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true
}
],
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
allowBoolean: true,
}
],
}
});
There is no other lint config files e.g. .eslintrc.json etc.
dev deps:
"@biomejs/biome": "^1.9.4",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/fragment-matcher": "^5.0.2",
"@graphql-codegen/typescript-operations": "^4.3.1",
"@graphql-codegen/typescript-react-apollo": "^4.3.2",
"@swc/core": "^1.9.2",
"@swc/helpers": "^0.5.15",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"dotenv": "^16.4.5",
"eslint": "^9.15.0",
"eslint-config-next": "^15.0.3",
"graphql": "^16.9.0",
"jest": "^29.7.0",
"postcss": "^8.4.49",
"shadcn": "^2.1.6",
"tailwindcss": "^3.4.15",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3",
"typescript-eslint": "^8.14.0"
Is this a false positive ? This warning was not previously there in Next 14
Share Improve this question asked Nov 19, 2024 at 16:33 VieleViele 2,3362 gold badges20 silver badges31 bronze badges 2 |1 Answer
Reset to default 0It helps to put the next-eslint stuff into a separate object:
export default tseslint.config(
{...},
{
plugins: {
'@next/next': eslintPluginNext
},
{
rules: ...eslintPluginNext.configs.recommended.rules
}
}
)
The linter treats separate objects differently in a somewhat obscure - but intended - manner (or some plugins themselves behave diffently depending on whether they're "alone" or not). If this alone doesn't do the trick, you can additionally try to move this logic at the buttom of the list/make it the last of the varargs, so it will take precendence over other values with the same names.
本文标签:
版权声明:本文标题:typescript - NextJS 15 warning during build: "The Next.js plugin was not detected in your ESLint config..." - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742413073a2470175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
export default tseslint.config({...}, { plugins: { '@next/next': eslintPluginNext }, { rules: ...eslintPluginNext.configs.recommended.rules } })
. I know that the linter treats separate objects differently in a somewhat obscure - but intended - manner, so it might to the trick here. – NotX Commented Nov 19, 2024 at 19:07