Next.js Discord

Discord Forum

Is it possible to setup local development eslint to run the same as npm run build eslint

Unanswered
Norwegian Forest Cat posted this in #help-forum
Open in Discord
Norwegian Forest CatOP
I am trying to Dockerize my NextJS app and I keep getting eslint errors when I have it run the build step. When I run the same command, either with npm run lint <file> or npx eslint <file>, I don't get any errors.

I can't find why this is linting is different for the different commands. Can anyone tell me as to why this is (and if there's any other differences to be aware of) and how you setup your develop vs. production builds to not get blindsided by build errors?

Thank you!

6 Replies

Norwegian Forest CatOP
My eslintrc.json is just this:
{ "extends": "next/core-web-vitals" }

And my package.json is just the standard installs:
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "14.2.4",
"next-auth": "^4.24.7",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.4",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
@joulev npm run lint and npm run build should run the exact same lint command though. are you sure the errors are eslint and not typescript? could you make a minimal reproduction repository?
Boston Terrier
With the new flat config adoption of eslint
if you create eslint.config.js and .eslintrc.json
the next linter takes precedence over .json and igonres .config.js

while npx eslint uses .config.js first.
Hence the difference on linting pattern.
@Boston Terrier With the new flat config adoption of eslint if you create `eslint.config.js` and `.eslintrc.json` the next linter takes precedence over `.json` and igonres `.config.js` while `npx eslint` uses `.config.js` first. Hence the difference on linting pattern.
oh i didn't consider eslint v9 or the .config.js system. OP: eslint-config-next does not support eslint v9 so if you use it you are at your own risk.

though OP used eslintrc.json so doesn't look like this is applicable to them.