Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to run simple-git-hooks with npx or npm exec #69

Open
motss opened this issue Feb 6, 2022 · 10 comments
Open

Fail to run simple-git-hooks with npx or npm exec #69

motss opened this issue Feb 6, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@motss
Copy link
Contributor

motss commented Feb 6, 2022

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
@toplenboren
Copy link
Owner

toplenboren commented Feb 10, 2022

Thanks for the detailed report, seems like an issue with package.json resolver. Gonna look into it on weekends

@maxschoolio
Copy link

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'
}

@toplenboren toplenboren added the bug Something isn't working label Nov 11, 2022
@robross0606
Copy link

robross0606 commented Aug 18, 2023

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.

@Muluk-m
Copy link

Muluk-m commented Mar 19, 2024

Any updates?

@toplenboren
Copy link
Owner

toplenboren commented Mar 20, 2024

Any updates?

I havent worked on this specific issue. Do you happen to encounter the same bug?

@Muluk-m
Copy link

Muluk-m commented Mar 21, 2024

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"

@toplenboren
Copy link
Owner

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..

@Muluk-m
Copy link

Muluk-m commented Mar 22, 2024

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..

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;

@toplenboren
Copy link
Owner

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?

@Muluk-m
Copy link

Muluk-m commented Mar 25, 2024

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?

Yes It exists, otherwise npm hooks will not execute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants