lefthook
lefthook copied to clipboard
Error: Cannot find module 'lefthook-linux-x64/bin/lefthook' on git commit after updating npm dependency to 1.6.10
:wrench: Summary
In an npm environment after updating lefthook to 1.6.10
package version I am no longer able to make commits on my Fedora Linux 39 Workstation machine. I don't have the issue on 1.6.8
.
I'm also not seeing any of these packages mentioned in the package lock in the node_modules folder:
"packages": {
...
"node_modules/lefthook": {
"optionalDependencies": {
"lefthook-darwin-arm64": "1.6.10",
"lefthook-darwin-x64": "1.6.10",
"lefthook-freebsd-arm64": "1.6.10",
"lefthook-freebsd-x64": "1.6.10",
"lefthook-linux-arm64": "1.6.10",
"lefthook-linux-x64": "1.6.10",
"lefthook-windows-arm64": "1.6.10",
"lefthook-windows-x64": "1.6.10"
}
}
}
Lefthook version
package.json dependency version 1.6.10
. Trying to call npx lefthook version -f
throws the same error mentioned below.
Steps to reproduce
- Upgrade dependency version to
1.6.10
-
npm i
- Try to make any commit
Expected results
Successful commit
Actual results
Error: Cannot find module 'lefthook-linux-x64/bin/lefthook'
Logs / Screenshots
+ '[' '' = 0 ']'
+ call_lefthook run prepare-commit-msg .git/COMMIT_EDITMSG message
++ git rev-parse --show-toplevel
+ dir=/home/redacted
++ uname
++ tr '[:upper:]' '[:lower:]'
+ osArch=linux
++ uname -m
++ sed s/aarch64/arm64/
+ cpuArch=x86_64
+ test -n ''
+ lefthook -h
+ test -f /home/redacted/node_modules/lefthook/bin/index.js
+ /home/redacted/node_modules/lefthook/bin/index.js run prepare-commit-msg .git/COMMIT_EDITMSG message
node:internal/modules/cjs/loader:1080
throw err;
^
Error: Cannot find module 'lefthook-linux-x64/bin/lefthook'
Require stack:
- /home/redacted/node_modules/lefthook/get-exe.js
- /home/redacted/node_modules/lefthook/bin/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Function.resolve (node:internal/modules/cjs/helpers:127:19)
at getExePath (/home/redacted/node_modules/lefthook/get-exe.js:17:18)
at Object.<anonymous> (/home/redacted/node_modules/lefthook/bin/index.js:9:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/redacted/node_modules/lefthook/get-exe.js',
'/home/redacted/node_modules/lefthook/bin/index.js'
]
}
Node.js v18.17.1
The same applies to a MacBook Pro with an M3 Pro on macOS Sonoma.
Error: Cannot find module 'lefthook-darwin-arm64/bin/lefthook'
Require stack:
- /Users/flntzr/workspace/exampleProject/node_modules/lefthook/get-exe.js
- /Users/flntzr/workspace/exampleProject/node_modules/lefthook/bin/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Function.resolve (node:internal/modules/helpers:190:19)
at getExePath (/Users/flntzr/workspace/exampleProject/node_modules/lefthook/get-exe.js:17:18)
at Object.<anonymous> (/Users/flntzr/workspace/exampleProject/node_modules/lefthook/bin/index.js:9:5)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/flntzr/workspace/exampleProject/node_modules/lefthook/get-exe.js',
'/Users/flntzr/workspace/exampleProject/node_modules/lefthook/bin/index.js'
]
}
Hey! Do you skip installation of optionalDependencies
? Could you share the way you install lefthook? It should usually go to devDependencies
.
Since 1.6.8 there was nothing special added to package management.
I am not entirely sure what happened here but after another npm install
it seems to be working with 1.6.10 as well. I did not skip any optionalDependencies
and lefthook is part of the devDependencies
.
The project in question is a monorepo using npm workspaces in combination with lerna and I suspect this has introduced some flakiness since we've seen a similar issue before. If it's relevant, it previously occurred with lightningcss-linux-arm64-gnu
.
@alexandrulesi Do you have a similar project setup, i.e. lerna and/or npm workspaces could be to blame?
I believe the error we're seeing here is related to this bug in the npm CLI and can be closed here.
I've had a similar issue on Windows 10 (but with a slightly different, windows-related error message, obviously).
Reverting to previous version fixed the issue.
Perhaps its related to #722, about virus scanners detecting the latest lefthook as a virus. Windows Security did warn me about an issue today, which went away after reverting to the previous version of lefthook.
I don't remember upgrading lefthook TODAY, when I started seeing problems, which is why I think it might be related to #722.
Partial package.json below, post reversion. (I'm sure anyone reading this would already understand how to revert to an early version, but just in case...)
"devDependencies": {
"lefthook": "1.6.11",
}
Hey! Does the issue still persist with the lefthook v1.6.16?
Just got a similar error on a macos x64 and version ^1.6.18
Cannot find module 'lefthook-darwin-x64/bin/lefthook'
So I'd say yes.
What package manager do you use?