cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm install does not run postinstall nor does it show name & version of installed pkg

Open JoernBerkefeld opened this issue 5 years ago • 16 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

when running npm install ... with a local package or a package on npm's servers it does not execute whatever is in scripts.postinstall

image

for image

Expected Behavior

in the 6.x releases it would state the line found in postinstall while executing it, means for the above example one should see

echo 'test postinstall'
test postinstall

It also printed the name & version of the package it just installed.

While the above example is trivial, it also extends to linking / running a *.js file with more complex logic via postinstall.

In #1905 a similar issue was mentioned for npm ci but somehow it still worked for npm install back then.

Steps To Reproduce

  1. prep a new package with the following package.json:
{
  "name": "npm-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "postinstall": "echo 'test postinstall'"
  },
  "author": "",
  "license": "ISC"
}
  1. try installing it into another package.
  2. see how it's not executing postinstall

Environment

  • OS: Windows 10
  • Node: 14.17.5
  • npm: 7.20.6

JoernBerkefeld avatar Aug 13 '21 12:08 JoernBerkefeld

Are you sure it's not executing it but suppressing output? In npm 7, dependencies can't spam the console with postinstall messages.

ljharb avatar Aug 13 '21 16:08 ljharb

It does execute. Run with --foreground-scripts or --loglevel=verbose and you'll see proof of this. We suppress the output if it exits with a zero status code, so that we can run multiple build scripts in parallel and not spam your terminal.

isaacs avatar Aug 17 '21 21:08 isaacs

hm. so what options are remaining to show an intro message after somebody executes npm install myPkg ? i get why this would be silenced during a generic npm install execution but do not understand why it is when I install a specific package

JoernBerkefeld avatar Aug 18 '21 06:08 JoernBerkefeld

The user could opt in to it, but there are no intro message options. Tell them what you need to tell them in your docs.

ljharb avatar Aug 18 '21 06:08 ljharb

hm. No, that's not correct. there isn't really an option to "opt-in" for the user because the above commands both show way more info than what the actually installed plugin is executing in the postinstall. in our case, we urge users to reload their IDE which is constantly forgotten despite being in the docs.

--foreground-scripts does show ALL the postinstall messages of sub-dependencies AND also npm warns. Means the screen is spammed with mostly unreadable info. meanwhile loglevel=verbose is absolutely useless for what I asked... I'm sure you know that.

And even without both parameters, the current output doesn't even acknowledge what version one just installed. While 6.x basically did what --foreground-scripts is doing, it also printed the version of the installed package which --foreground-scripts in 7.x does not, nor does the standard output for that matter.

--> while you obviously intended good I don't believe that's what you accomplished here and urge to rethink it.

JoernBerkefeld avatar Aug 18 '21 06:08 JoernBerkefeld

What is your use case for an intro message? As a user, I would never, ever want that.

ljharb avatar Aug 18 '21 06:08 ljharb

" in our case, we urge users to reload their IDE which is constantly forgotten despite being in the docs." why? because our package works best together with VSCode (clearly mentioned in the docs) and requires a list of vscode extensions to actually provide the service the user expects (eslint, prettier, ...). The restart of the IDE makes vscode prompt the user to install or review the recommendations

JoernBerkefeld avatar Aug 18 '21 06:08 JoernBerkefeld

If they won't read the docs then why would they read the install message?

ljharb avatar Aug 18 '21 16:08 ljharb

:| #motivation

people are waiting for the install to finalize and right now it doesn't even output a "hey, what you just tried installing is now installed" anymore - contrary to 6.x

and whatever message I output as part of postinstall can (& does) use colors, making sure people can see it easily. The docs on the other hand are veeeery long and people tend to skip steps unintentionally.

JoernBerkefeld avatar Aug 19 '21 09:08 JoernBerkefeld

im requesting to re-open this issue

JoernBerkefeld avatar Aug 24 '21 05:08 JoernBerkefeld

Please re-open this issue. Running npm 8.1.0 and pre/post npm scripts are no longer able to echo to the terminal. This is a huge regression.

atomless avatar Oct 28 '21 16:10 atomless

@atomless this happened in v7.0.0 and was very intentional, and I don't believe there's any plans to change it.

ljharb avatar Oct 28 '21 17:10 ljharb

I have the same problem. In my case, the postinstall script will be executed a few minutes. So I'd like to print some messages for user to tell them the dependency is executing something expected rather than still frame. If not it will makes them feel meeting unknown error.

ZyJoey avatar Jan 21 '22 08:01 ZyJoey

It does execute. Run with --foreground-scripts or --loglevel=verbose and you'll see proof of this. We suppress the output if it exits with a zero status code, so that we can run multiple build scripts in parallel and not spam your terminal.

It is also not executing then. i have run all types of higher log levels and there is nothing to indicate that it is being run, nor is there any creation of the items which neccesitate the use of the postinstall.

hbaldwinRPT avatar Dec 28 '23 23:12 hbaldwinRPT

status on this?

dhowe avatar Apr 27 '25 00:04 dhowe

any workarounds on this, almost 5 years later?

anshxlm avatar Jul 10 '26 06:07 anshxlm