Search code examples
pre-commit-hookhusky

Pre-Commit Error 'Cannot Find Module - npx-cli.js' When Using Husky


I am trying to run a pre-commit hook that checks check my style using husky and stylelint but when I try to commit a file GitKracken fails. The log reads as follows:

Error: Cannot find module C:\Users\name\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT FOUND',
requireStack: []    
}

I am running npm version: 6.13.4 and node version: 12.14.1. From my research npx is installed with npm in any versions over 5 or so already. I've also tried globally installing npx as well but it fails to install claiming file already exists.

I am sure it is a path problem or perhaps I am using husky incorrectly but figured I'd reach to to see if anyone knows why I'm having issues getting this to work. Thanks for any insights you may have.

package.json

// I've tested rand the stylelint command manually and it does check for stylelint errors

{
"husky": {
    "hooks": {
      "pre-commit": "node ./node_modules/stylelint/bin/stylelint.js ./src/scss/**/*.scss"
    }
  }
}

Solution

  • You have very likely updated Husky from v4 to v7, look at migration guide.