npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.53k stars 3.2k forks source link

[BUG] npm install <local folder> does not run postinstall #4804

Closed oshi97 closed 1 year ago

oshi97 commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

Installing a local npm package does not run the postinstall script.

Expected Behavior

The postinstall script runs, and in this case creates a new file

Steps To Reproduce

  1. git clone https://github.com/oshi97/install-links.git
  2. git checkout postinstall
  3. cd parent
  4. npm i ../child
  5. expected to see a new test.txt file created, but no file was created

Environment

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /Users/oshi/.nvm/versions/node/v16.14.2/bin/node ; node version = v16.14.2 ; npm local prefix = /Users/oshi/techops/install-links-test/parent ; npm version = 8.7.0 ; cwd = /Users/oshi/techops/install-links-test/parent ; HOME = /Users/oshi ; Run npm config ls -l to show all defaults.

manigedit commented 2 years ago

@oshi97 I'm unable to reporoduce this issue. In my case test.txt file gets created. Please share more details / anything I'm missing to reproduce this issue.

image
Niryo commented 2 years ago

happens to me as well, node 16.15.0, npm 8.5.5. I also tried the steps given here to reproduce and I can confirm the issue. I am running on macOS Monterey (MacBook Pro 16-inch, 2019) image

oshi97 commented 2 years ago

@oshi97 I'm unable to reporoduce this issue. In my case test.txt file gets created. Please share more details / anything I'm missing to reproduce this issue.

image

It could be your npm version?

oshi97 commented 2 years ago

I've noticed that npm install <pkg-name> seems to not run the postinstall for instances where node_modules have not changed. For instance, if I run npm install blah as a new dependency, the postinstall would run, but running npm install blah will not run the postinstall. However if I try to npm install blah@aDifferentVersion the postinstall will run. From an outside perspective I feel like this could be related to npm installing a local folder, since a local folder install will create a symlink instead of copying local files, and may even be intentional behavior.

bennieswart commented 2 years ago

We're seeing the same issue on node 16.15.0 with npm 8.5.5. It worked previously on node 16.14.2 with npm 8.5.0.

tleunen commented 2 years ago

Same here. postinstall doesn't run on Node 16.15.0 with npm 8.5.5, but it works fine in node 16.14.2 with npm 8.5.0

The setup is with NPM workspaces, where one of the workspace is a dependency of another and it contains a postinstall script.

Updating npm to 8.10.0 seems to fix this issue for me tho

qq326943819 commented 2 years ago

I also encountered a similar problem. When installing packages like yorkie, the life cycle of install, including install and postinstall, was not triggered.

node: 16.15.0 npm: 8.5.5

When switching to version 14, it works normally.

CSchulz commented 1 year ago

I have encountered the same issue on Windows 10 Pro with node 16.15.0 and npm 8.5.5.

I thought I have done anything wrong with my package.json until I have searched this behavior as an issue.

ariym commented 1 year ago

This issue is still present in node v19.9.0 (npm v9.6.3)

I can only get the postinstall script to run by reverting to an earlier version of node.