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

[BUG] Hook Scripts Not Run on npm install #2692

Closed
karlhorky opened this issue Feb 13, 2021 · 7 comments
Closed

[BUG] Hook Scripts Not Run on npm install #2692

karlhorky opened this issue Feb 13, 2021 · 7 comments
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release

Comments

@karlhorky
Copy link
Contributor

First of all, thanks for all of the work being done on the npm CLI and the ecosystem! Tons of new amazing things in v7.

Current Behavior:

Hook scripts (documented in the docs here) seem to no longer get run for npm v7.

For example, an executable file at node_modules/.hooks/postinstall with the following contents not get run:

#!/usr/bin/env node
console.log('ran hook');

I also tried this:

#!/usr/bin/env bash
echo 'ran hook'

This will not get run during npm install or npm install <pkg name>

Expected Behavior:

The hook scripts should be run

Steps To Reproduce:

  1. Create a new package with one of the file contents above in an executable file under node_modules/.hooks/postinstall
  2. Run npm install
  3. Hook script does not get run

Environment:

  • OS: macOS 11.2.1
  • Node: 15.8.0
  • npm: 7.5.4

Alternatives considered

Maybe Hook Scripts are no longer supported? In this case, they should be removed from the documentation.

@karlhorky karlhorky added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Feb 13, 2021
@darcyclarke darcyclarke added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Feb 24, 2021
@darcyclarke darcyclarke added this to the OSS - Sprint 25 milestone Feb 24, 2021
@darcyclarke darcyclarke added Priority 1 high priority issue and removed Priority 2 secondary priority issue labels Apr 7, 2021
@Goobles
Copy link

Goobles commented Apr 8, 2021

npm install has become more "silent" and doesn't output the stdout of your scripts during installation.
Your hook script might or might not be executing without you knowing it. Verify by writing something to a logfile in your script instead of using echo

@augustobmoura
Copy link
Contributor

I can confirm that lifecycle hooks do not run, this is probably a regression and is impacting our users in asdf-nodejs. There's any work on going to fix this?

@RussCoder
Copy link

In my case install and postinstall hooks work, but no logs are printed to the console. I use npm 7.11.1
But preuinstall and uninstall hooks don't work at all.

Actually, it would be nice if logs were printed to the console, because there can be useful messages for the user. Especially, the messages which are printed by the postinstall script.

npm can be silent in case of its own logs, but I think it's logical to print all messages from user-defined scripts.

@ljharb
Copy link
Contributor

ljharb commented Apr 29, 2021

@RussCoder the entire reason npm 7 changed this was to prevent user-defined scripts from injecting ads into people's terminals.

@augustobmoura
Copy link
Contributor

install and postinstall script fields in package.json still works, the issue is with postinstall script files in the directory node_modules/.hooks that should run for every package. Still not working in the latest version. @ljharb do you think this is a issue that needs of arborist or the npm cli? I'm thinking about giving a try in solving it, I saw that arborist has some code for hooks but I didn't went too deep

@wraithgar
Copy link
Member

node_modules/.hooks was removed from the docs in the cli repo, and the docs site will reflect when it next rebuilds and deploys.

@karlhorky
Copy link
Contributor Author

Ok thanks @wraithgar !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

7 participants