Fail to run `simple-git-hooks` with `npx` or `npm exec`
Issues
Running simple-git-hooks with npx or npm exec causes the installation to fail.
$ npx -y simple-git-hooks@latest
> [email protected] postinstall
> node ./postinstall.js
node:internal/fs/utils:344fy:simple-git-hooks: sill audit bulk request { 'simple-git-hooks': [ '2.7.0' ] }
throw err;
^
Error: ENOENT: no such file or directory, stat '/Users/user/.npm/_npx/318daabbad435bbd/package.json'
at Object.statSync (node:fs:1536:3)
at _getPackageJson (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/simple-git-hooks.js:174:13)
at checkSimpleGitHooksInDependencies (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/simple-git-hooks.js:102:34)
at postinstall (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/postinstall.js:15:9)
at Object.<anonymous> (/Users/user/.npm/_npx/318daabbad435bbd/node_modules/simple-git-hooks/postinstall.js:24:1)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/Users/user/.npm/_npx/318daabbad435bbd/package.json'
}
Node.js v17.2.0
Expected behavior
simple-git-hooks should run correctly using npx or npm exec locally.
Actual behavior
Running npx -y simple-git-hooks or npm exec -y -- simple-git-hooks@latest throws error.
Debugging details
$ npx -y envinfo
System:
OS: macOS 12.2
CPU: (10) arm64 Apple M1 Max
Memory: 13.90 GB / 64.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.2.0
npm: 8.1.4
Thanks for the detailed report, seems like an issue with package.json resolver. Gonna look into it on weekends
similar error while deploying to google app engine
Running "yarn install --non-interactive --prefer-offline --modules-folder=/layers/google.nodejs.yarn/yarn_modules/node_modules --frozen-lockfile (PATH=/layers/google.nodejs.yarn/yarn_engine/bin:/layers/google.nodejs.runtime/node/bin:/builder/google-cloud-sdk/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/layers/google.nodejs.yarn/yarn_modules/node_modules/.bin)"
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "webpack@^5.0.0".
[4/4] Building fresh packages...
error /layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks: Command failed.
Exit code: 1
Command: node ./postinstall.js
Arguments:
Directory: /layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks
Output:
node:internal/fs/utils:347
throw err;
^
Error: ENOENT: no such file or directory, stat '/layers/google.nodejs.yarn/yarn_modules/package.json'
at Object.statSync (node:fs:1588:3)
at _getPackageJson (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/simple-git-hooks.js:174:13)
at checkSimpleGitHooksInDependencies (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/simple-git-hooks.js:102:34)
at postinstall (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/postinstall.js:15:9)
at Object.<anonymous> (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/postinstall.js:24:1)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/layers/google.nodejs.yarn/yarn_modules/package.json'
}
Similar error when calling npx simple-git-hooks from Windows cmd prompt if you don't have it installed locally or globally already and you're on npx version 6.:
C:\Code\my-code>npx simple-git-hooks
internal/fs/utils.js:332
throw err;
^
Error: ENOENT: no such file or directory, stat 'C:\Users\me\AppData\Roaming\npm-cache\_npx\9096\package.json'
at Object.statSync (fs.js:1132:3)
at _getPackageJson (C:\Users\me\AppData\Roaming\npm-cache\_npx\9096\node_modules\simple-git-hooks\simple-git-hooks.js:190:13)
at checkSimpleGitHooksInDependencies (C:\Users\me\AppData\Roaming\npm-cache\_npx\9096\node_modules\simple-git-hooks\simple-git-hooks.js:113:34)
at postinstall (C:\Users\me\AppData\Roaming\npm-cache\_npx\9096\node_modules\simple-git-hooks\postinstall.js:18:9)
at Object.<anonymous> (C:\Users\me\AppData\Roaming\npm-cache\_npx\9096\node_modules\simple-git-hooks\postinstall.js:27:1)
at Module._compile (internal/modules/cjs/loader.js:1114:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:979:32)
at Function.Module._load (internal/modules/cjs/loader.js:819:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {
errno: -4058,
syscall: 'stat',
code: 'ENOENT',
path: 'C:\\Users\\me\\AppData\\Roaming\\npm-cache\\_npx\\9096\\package.json'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node ./postinstall.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\me\AppData\Roaming\npm-cache\_logs\2023-08-18T22_04_12_642Z-debug.log
Install for [ 'simple-git-hooks@latest' ] failed with code 1
It doesn't seem to happen with newer versions of npx though.
Any updates?
Any updates?
I havent worked on this specific issue. Do you happen to encounter the same bug?
Any updates?
I havent worked on this specific issue. Do you happen to encounter the same bug?
Yes, This is the only way I can set it up to prevent pipeline interruptions "prepare": "npx simple-git-hooks || true"
Yes, This is the only way I can set it up to prevent pipeline interruptions
"prepare": "npx simple-git-hooks || true"
Hey, can you please share some info on environment? Do you have package.json file in pipeline?
In the meantime... I think I'll cook a way to make script fail silently if package.json is not found..
Yes, This is the only way I can set it up to prevent pipeline interruptions
"prepare": "npx simple-git-hooks || true"Hey, can you please share some info on environment? Do you have
package.jsonfile in pipeline?In the meantime... I think I'll cook a way to make script fail silently if package.json is not found..
my host machine is running on node v14.21.3 (npm v6.14.18),
my pipline flow looks something like this, "prepare": "npx simple-git-hooks || true", "prepublishOnly": "pnpm install && pnpm build" npx simple-git-hooks will execute before pnpm install, and I can replicate this on my mac;
Thanks for the info!
Can you please provide one small detail: script crashes because it couldn't find package.json file.. Do you have package.json file inside your file system in your pipeline?
Thanks for the info!
Can you please provide one small detail: script crashes because it couldn't find package.json file.. Do you have
package.jsonfile inside your file system in your pipeline?
Yes It exists, otherwise npm hooks will not execute.