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

The package can't be installed #256

Closed
mlomb opened this issue Aug 13, 2024 · 4 comments
Closed

The package can't be installed #256

mlomb opened this issue Aug 13, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mlomb
Copy link

mlomb commented Aug 13, 2024

Hey, I was debugging some problem (#117) in chat-analytics (which uses whatsapp-chat-parser) and found out the package can't be installed due the postinstall script.

> npm i whatsapp-chat-parser
npm error code 1
npm error path C:\Users\Lombi\node_modules\whatsapp-chat-parser
npm error command failed
npm error command C:\Windows\system32\cmd.exe /d /s /c husky install
npm error 'husky' is not recognized as an internal or external command,
npm error operable program or batch file.

npm error A complete log of this run can be found in: C:\Users\Lombi\AppData\Local\npm-cache\_logs\2024-08-13T17_30_41_373Z-debug-0.log

The problem persists when trying to install chat-analytics.

npm i -g chat-analytics
npm error code 1
npm error path C:\Users\Lombi\AppData\Roaming\npm\node_modules\chat-analytics\node_modules\whatsapp-chat-parser
npm error command failed
npm error command C:\Windows\system32\cmd.exe /d /s /c husky install
npm error 'husky' is not recognized as an internal or external command,
npm error operable program or batch file.

npm error A complete log of this run can be found in: C:\Users\Lombi\AppData\Local\npm-cache\_logs\2024-08-13T17_33_06_953Z-debug-0.log

I recommend removing the postinstall script. I usually have those disabled, but forgot to do so in this machine.

😃

@Pustur
Copy link
Owner

Pustur commented Aug 13, 2024

Hi @mlomb

Can you tell me what version are you trying to install?

Edit: I guess 4.0.0 looking at your package.json

I'll look into this

@mlomb
Copy link
Author

mlomb commented Aug 13, 2024

This is interesting 🤔

PS C:\Users\Lombi> npm i whatsapp-chat-parser
npm error code 1
npm error path C:\Users\Lombi\node_modules\whatsapp-chat-parser
npm error command failed
npm error command C:\Windows\system32\cmd.exe /d /s /c husky install
npm error 'husky' is not recognized as an internal or external command,
npm error operable program or batch file.

npm error A complete log of this run can be found in: C:\Users\Lombi\AppData\Local\npm-cache\_logs\2024-08-13T17_49_47_287Z-debug-0.log
PS C:\Users\Lombi> npm i whatsapp-chat-parser@4.0.0
npm error code 1
npm error path C:\Users\Lombi\node_modules\whatsapp-chat-parser
npm error command failed
npm error command C:\Windows\system32\cmd.exe /d /s /c husky install
npm error 'husky' is not recognized as an internal or external command,
npm error operable program or batch file.

npm error A complete log of this run can be found in: C:\Users\Lombi\AppData\Local\npm-cache\_logs\2024-08-13T17_49_50_448Z-debug-0.log
PS C:\Users\Lombi> npm i whatsapp-chat-parser@latest

added 1 package, and audited 2 packages in 616ms

found 0 vulnerabilities

@Pustur
Copy link
Owner

Pustur commented Aug 13, 2024

First of all, i can reproduce the issue on my windows machine

Secondly, it's clear(er) what's happening now after a bit of research

In my package, i used the husky package to run a script on precommit (format + lint + tests)
Husky is supposed to run only in development, which is why i used the pinst package to disable the postinstall script when publishing the package to npm (pinst does this by renaming the field to _postinstall so it doesn't run)

Well apparently the metadata on npm's servers and the one contained in my package.json file is different, in theirs the field still has the correct name

$ npm view whatsapp-chat-parser@4.0.0 scripts
{
  build: 'tsup',
  test: 'TZ=UTC vitest run',
  'test:watch': 'TZ=UTC vitest watch',
  'test:coverage': 'TZ=UTC vitest run --coverage',
  lint: 'tsc && eslint .',
  format: 'prettier --write .',
  'format:staged': 'pretty-quick --staged',
  prepack: 'npm run build && pinst --disable',
  postpack: 'pinst --enable',
  prepublishOnly: 'npm run build && npm t && pinst --disable',
  postinstall: 'husky install', # this is supposed to be "_postinstall" just like the published package.json!
  postpublish: 'pinst --enable'
}

This has been explained much better by this post:

https://gist.github.com/djcsdy/2f5a287b3ba16f2a8f0312f45588e6ce

Which I found here:

typicode/pinst#23

To fix this I will have to reevaluate how i run these scripts, and probably there are better ways to do that nowadays.

Thanks a lot for bringing this to my attention, I'll try to fix it as soon as possible.

@Pustur Pustur added the bug Something isn't working label Aug 13, 2024
@Pustur Pustur self-assigned this Aug 13, 2024
@Pustur Pustur closed this as completed in d3465e0 Aug 14, 2024
@Pustur
Copy link
Owner

Pustur commented Aug 14, 2024

Hi @mlomb
The problem should be gone in the new version.

Querying 4.0.0:

➜ npm view whatsapp-chat-parser@4.0.0 scripts
{
  lint: 'tsc && eslint .',
  test: 'TZ=UTC vitest run',
  build: 'tsup',
  format: 'prettier --write .',
  prepack: 'npm run build && pinst --disable',
  postpack: 'pinst --enable',
  'test:watch': 'TZ=UTC vitest watch',
  postinstall: 'husky install',
  postpublish: 'pinst --enable',
  'format:staged': 'pretty-quick --staged',
  'test:coverage': 'TZ=UTC vitest run --coverage',
  prepublishOnly: 'npm run build && npm t && pinst --disable'
}

Querying 4.0.1:

➜ npm view whatsapp-chat-parser@4.0.1 scripts
{
  build: 'tsup',
  test: 'cross-env TZ=UTC vitest run',
  'test:watch': 'cross-env TZ=UTC vitest watch',
  'test:coverage': 'cross-env TZ=UTC vitest run --coverage',
  lint: 'tsc && eslint .',
  format: 'prettier --write .',
  prepublishOnly: 'npm run build && npm t'
}

How did I solve it?

I removed the dependencies from the packages mentioned above and removed some dev scripts.
The important quality checks are still in CI anyway

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

2 participants