The latest version of husky
is broken in npm v7. I'm not sure if this regression is intended or not, i.e. if Husky needs to be updated or npm needs a bugfix.
~ npx husky-run pre-commit
npm ERR! could not determine executable to run
npm ERR! A complete log of this run can be found in:
...
~ npx husky-run pre-commit
husky > pre-commit (node v14.10.1)
Hello World!
...
npm init -y
inside ithusky
with npm i -D husky
echo '{ "hooks": { "pre-commit": "echo Hello World!" } }' > .huskyrc.json
npx husky-run pre-commit
This might be related to #1834
@rafgraph On windows, I had no issues for hooks to be installed with Husky. When I used WSL on Ubuntu though, I had to use sudo
for hooks to be installed, otherwise I had errors in the npm install log. So I don't think this is strictly related, since the error above can be reproduced by simply running npx husky-run pre-commit
without hooks being installed at all.
@csvn can you try installing the latest beta & seeing if you can repro? npm i -g npm@next-7
. If you're still experiencing this, we'd love the debug.log
Hi @darcyclarke. Attached the output for the debug.log
for the reproduction steps in the description.
0 verbose cli [
0 verbose cli '/usr/local/bin/node',
0 verbose cli '/usr/local/share/npm-global/lib/node_modules/npm/bin/npm-cli.js',
0 verbose cli 'exec',
0 verbose cli '--',
0 verbose cli 'husky-run',
0 verbose cli 'pre-commit'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/usr/local/share/npm-global/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/workspaces/npm-husky-test/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/root/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 1ms
13 timing config:load:global Completed in 1ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setEnvs Completed in 1ms
17 timing config:load Completed in 7ms
18 verbose npm-session 53798df1482fef51
19 timing npm:load Completed in 13ms
20 http fetch GET 200 https://registry.npmjs.org/husky-run 832ms
21 timing command:exec Completed in 840ms
22 verbose stack Error: could not determine executable to run
22 verbose stack at getBinFromManifest (/usr/local/share/npm-global/lib/node_modules/npm/lib/exec.js:210:23)
22 verbose stack at exec (/usr/local/share/npm-global/lib/node_modules/npm/lib/exec.js:98:15)
23 verbose cwd /workspaces/npm-husky-test
24 verbose Linux 4.19.128-microsoft-standard
25 verbose argv "/usr/local/bin/node" "/usr/local/share/npm-global/lib/node_modules/npm/bin/npm-cli.js" "exec" "--" "husky-run" "pre-commit"
26 verbose node v14.10.1
27 verbose npm v7.0.0-beta.12
28 error could not determine executable to run
29 verbose exit 1
I ran this within a Docker Devcontainer and WSL in VSCode. Environment info:
root@cc760b824422:/workspaces/npm-husky-test# npm -v
7.0.0-beta.12
root@cc760b824422:/workspaces/npm-husky-test# node -v
v14.10.1
This is the same for Windows, npm 7.0.0-beta.12
node v14.8.0
:
0 verbose cli [
0 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli 'exec',
0 verbose cli '--',
0 verbose cli 'husky-run',
0 verbose cli 'pre-commit'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 0ms
5 timing config:load:builtin Completed in 0ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:C:\Users\Christian\Dev\@apptus\esales-fashion\.npmrc Completed in 1ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:C:\Users\Christian\.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:C:\Program Files\nodejs\etc\npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setEnvs Completed in 1ms
17 timing config:load Completed in 6ms
18 verbose npm-session 3e0f43b059d2f137
19 timing npm:load Completed in 15ms
20 http fetch GET 200 https://registry.npmjs.org/husky-run 85ms
21 timing command:exec Completed in 95ms
22 verbose stack Error: could not determine executable to run
22 verbose stack at getBinFromManifest (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:210:23)
22 verbose stack at exec (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:98:15)
23 verbose cwd C:\Users\Christian\Dev\@apptus\esales-fashion
24 verbose Windows_NT 10.0.19041
25 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "exec" "--" "husky-run" "pre-commit"
26 verbose node v14.8.0
27 verbose npm v7.0.0-beta.12
28 error could not determine executable to run
29 verbose exit 1
the issue here is that npx
thinks you're trying to run husky-run the package rather than husky-run
the bin script that's part of husky.
what you'll want to do to run the husky-run
script within husky
itself, is
npx -p husky husky-run
which informs npx
which package contains the bin, and I can confirm works correctly
I get this same error could not determine executable to run
when running husky
as a pre-commit hook. Error log attached.
2020-10-02T00_36_01_041Z-debug.log
husky
was installed with npm v6 (because of #1834), the pre-commit hook successfully setup. It is setup in package.json
to run lint-staged
as described in prettier
docs. This works fine with npm v6
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*": "prettier --write --ignore-unknown"
}
@nlf running npx husky-run
is just for illustrating the problem. The real issue is that the hooks running with Husky fails when Husky executes them. So it is really the package that needs updating, if this issue is "working as intended". npx
with npm v6 managed to find /node_modules/.bin/husky-run
and run correctly. So this is a breaking change, and I was just curious if this is intended.
So in my mind, there are two options:
npx <command>
can find scripts in /node_modules/.bin
if they match firstI just wanted clarity which option is the right one, before opening an issue on Husky with this.
To add another data point, I think I'm running into the same issue with the vue-cli-service
bin script (which works in npm@6).
$ npx vue-cli-service serve
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/vue-cli-service - Not found
npm ERR! 404
npm ERR! 404 'vue-cli-service@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
$ npx vue serve
npm ERR! could not determine executable to run
Based on nlf's comment there is a workaround until this is fixed in npm@7:
$ npx -p @vue/cli-service vue-cli-service serve
we published v7.0.0-rc.4 today that restores the old behavior of npx
with regards to already installed scripts and should resolve these issues.
you can update with npm i -g npm@next-7
and let us know how it goes!
Thanks @nlf! I can verify that my Husky hooks now works again, same as with npm v6.
Most helpful comment
we published v7.0.0-rc.4 today that restores the old behavior of
npx
with regards to already installed scripts and should resolve these issues.you can update with
npm i -g npm@next-7
and let us know how it goes!