VSCode & FNM - pre-commit: npx: not found
Asked Answered
N

2

6

I'm using VSCode and FNM (Fast Node Manager) instead of NVM. The issue seems to be that VSCode fails to see npx while committing from Source Control and throws out the following error:

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
.husky/pre-commit: 6: npx: not found
husky - pre-commit hook exited with code 127 (error)

I've looked at other answers here and they all seem to be pointing towards a misconfigured path for NVM but I'm currently not using NVM. I'm on fnm: https://github.com/Schniz/fnm

Is there any way I can fix this?

Nisan answered 14/2, 2022 at 6:15 Comment(0)
C
3

I had the same problem after switching from nvm. Try to add eval "$(fnm env --use-on-cd)" in your .zshrc file.

For me it was the solution. Maybe it helps you as well.

Colincolinson answered 28/3, 2022 at 20:22 Comment(0)
A
0

Quoting Husky docs:

Husky sources ~/.config/husky/init.sh before each Git hook. Copy your version manager initialization code here to ensure it runs in GUIs.

The exact solution will vary depending on the specifics of your setup, but in my case (macOS, fnm installed with brew), I solved this by putting the following in ~/.config/husky/init.sh:
(code ~/.config/husky/init.sh to open in VS Code)

eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(fnm env --use-on-cd)"

(first line was sourced from ~./zprofile, second from ~/.zshrc)

References:

Ambassadoratlarge answered 15/8 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.