NextJS - Linter with lint-staged not working

Viewed 457

I've set up lint-staged and husky with NextJS. When we run yarn lint, it calls yarn next lint under the hood and it works. When we call yarn lint-staged, we receive an error:

āœ– yarn lint:
> Couldn't find a `pages` directory. Please create one under the project root

The point is that pages directory exists under src and it should work. What is going on?

package.json:

{
  "scripts": {
    "lint": "next lint"
  },
  "lint-staged": {
    "src/**/*.{ts,tsx}": [
      "yarn lint"
    ]
  }
}
1 Answers

use "eslint" instead of "yarn lint" under lint-staged.

I believe next lint has some inherent configurations that aren't compatible with lint-staged.

"eslint" catches the intended error during pre-commits

package.json

{
  "scripts": {
    "lint": "next lint"
  },
  "lint-staged": {
    "src/**/*.{ts,tsx}": [
      "eslint"
    ]
  }
}
Related