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] npm 7.x executes package.json preinstall script after installing dependencies #2253

Closed
Ngorror opened this issue Nov 28, 2020 · 5 comments
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@Ngorror
Copy link

Ngorror commented Nov 28, 2020

Current Behavior:

when you run npm install, package.json preinstall script will be executed after dependencies installation

Expected Behavior:

package.json preinstall script must be executed before dependencies installation.

Steps To Reproduce:

Execute the following commands to clone my test repository and run npm install to reproduce the problem

git clone https://github.com/Ngorror/npm-preinstall-bug.git
cd npm-preinstall-bug
npm install

OR

  1. create package.json file in empty directory with the following content:
{
  "name": "npm-preinstall-bug",
  "version": "1.0.0",
  "dependencies": {
    "mongodb": ">=3.6.0"
  },
  "description": "",
  "main": "index.js",
  "scripts": {
    "preinstall": "rm -f -R node_modules"
  },
  "author": "",
  "license": "ISC"
}
  1. execute npm install
  2. npm will install dependencies and then it will execute preinstall script. as result node_modules directory will be deleted.

Environment:

  • OS: Linux Mint 20.04, Windows 10
  • Node: >=17.0.0
  • npm: >= 7.0.2
@Ngorror Ngorror 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 Nov 28, 2020
@ljharb
Copy link
Contributor

ljharb commented Nov 29, 2020

Can you confirm the bug still happens in v7.0.15?

@Ngorror
Copy link
Author

Ngorror commented Nov 29, 2020

yep
I stumbled on this on my first install of node 15.0.0, npm 7.0.2 few months ago.
Since then I procrastinated to report the problem.
yesterday I installed node 15.3.0, npm 7.0.14
now I installed 7.0.15 - the problem is still here.

@darcyclarke
Copy link
Contributor

@Ngorror this is actually working as intended; If, as your example alludes, you want to do a clean install - you can/should use npm ci

@pmunin
Copy link

pmunin commented Aug 31, 2021

Can someone reopen this issue? preinstall still not running before dependencies installation

@bugsounet
Copy link

Not always fixed ? (and same bug in v8)

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

No branches or pull requests

5 participants