sh: husky: command not found

See original GitHub issue

Context

I’ve setup a node project with husky but when my collegue tries to run npm install on his Mac he gets the following error :

noa-be@1.0.0 prepare
husky install

sh: husky: command not found
npm ERR! code 127
npm ERR! path /Users/X/Desktop/Workspace/project
npm ERR! command failed
npm ERR! command sh -c husky install

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/X/.npm/_logs/2021-04-12T13_07_25_842Z-debug.log

These are the relevant package.json parts:

{
    "scripts": {
        "prepare": "husky install"
    },
    "devDependencies": {
        "husky": "^5.2.0",
    }
}

I thought this would be enough for husky to be installed when running npm install, but it’s not. What am I missing?

Thank you!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
raphaelsetincommented, Mar 23, 2022

@ctsstc That didn’t work for me.

The following worked (and is cross platform too):

"prepare": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install",
5reactions
vintproxcommented, Sep 14, 2021

Everything seems alright on local machine, but when I deploy on Heroku, I get this:

...
remote: -----> Installing dependencies
remote:        Installing node modules
remote:
remote:        > drcm-bot@0.1.0 prepare /tmp/build_b8e6fb4d
remote:        > husky install
remote:
remote:        sh: 1: husky: not found
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! syscall spawn
remote:        npm ERR! file sh
remote:        npm ERR! errno ENOENT
remote:        npm ERR! drcm-bot@0.1.0 prepare: `husky install`
remote:        npm ERR! spawn ENOENT
...

The problem was that husky, being installed in devDependencies, gets stripped away if you set NPM_CONFIG_PRODUCTION=true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sh: husky: command not found - node.js - Stack Overflow
Temporarily remove the "prepare": "husky install" script from the package.json file. · Run npm i ( npm install ). Dependencies installed ...
Read more >
husky: command not found with npm install --production
Recently, while attempting to build a Docker container, I ran into a bit of a dilemma. Upon running npm install --production I was...
Read more >
Husky - Git hooks
Command not found ... If you're running Git from an app and the command can be found in your terminal, this means that...
Read more >
husky - npm
Start using husky in your project by running `npm i husky`. There are 2595 other projects in the npm registry using husky.
Read more >
Getting Started with Git Hooks and Husky | Tower Blog
.husky/pre-commit: line 4: npx: command not found husky - pre-commit hook exited with code 127 (error) husky - command not found in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found