0

I have lint-staged installed in a multi-package repository.

The structure is:

|-- package.json
|-- package-one
   |-- package.json
   |-- javascript
|-- package-two
   |-- package.json
   |-- javascript

I have the same setup in a different repo on the same machine and the below works with no errors.

I am using lint-staged to run eslint on pre-commit. Each sub-package has a lint npm script in it.

In the other repository I call lint-staged on each package without error, however, in this repo when running against a stage file it:

  • correctly identifies the staged file
  • produces the error npm could not be found. Try npm install npm.
  • if I change the npm script out to simply be "git add" then the error is git could not be found. Try npm install git.

Running which npm produces the same results in the working and non-working repos.

Running npm install or any other npm command works when ran directly, just not when ran through lint-staged.

I am at a loss as to what may be causing this?

    "devDependencies": {
        "husky": "^2.4.1",
        "lint-staged": "^8.2.1",
    },
    "lint-staged": {
        "packages/package-name/**/*.{js,jsx}": [
            "npm run --silent lint --prefix packages/package-one"
        ]
    },
    "husky": {
        "hooks": {
            "pre-commit": "lint-staged"
        }
    }
glenrothes
  • 1,543
  • 1
  • 14
  • 17
  • Do you have `npm` installed globally? – Ru Chern Chong Jun 30 '19 at 16:00
  • Yes, for several months. I use `nvm` to manage it across repos. In both the repo that works and the one that does not `which npm` results in: `/Users/username/.nvm/versions/node/v8.16.0/bin/npm` – glenrothes Jun 30 '19 at 16:49

0 Answers0