npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm prune removes local file path installs

Not sure if this is a feature or a bug, but when a package.json dependency uses the local file syntax, npm prune --production will remove it.

{
  "dependencies": "file://path/to/lib"
}
$ npm prune --production

This will remove the package from node_modules. Is this expected? If so, is there a way to prevent this from happening?

Specs:

Related issues:


Only relative file: specs are supported. Maybe that’s what’s going on for you? :slight_smile:

So: file:foo/bar.


Oops thats just a typo, its actually relative, file://../path/to/*.tgz. My mistake.


I believe the leading // should be dropped, like with GitHub dependencies (github:foo/bar#rev).


I should clarify that I didn’t add it myself. This was added by npm after running the npm install —save ../path/to/foo.tgz command.

The docs do show that it is file:.. but I’m not modifying it.

So I made a simple use case of just an app and library and it does work as intended. However, for my larger project with the same commands, prune seems to be removing the locally installed package. I’m not sure why.

List of commands I’m running (assuming lib and app folders with package.json respectively. App does not depend on lib by default:

  1. cd lib
  2. npm pack
  3. cd …/app
  4. npm i --save …/lib/*.tgz
  5. npm i
  6. npm prune --production

Is there a good way to debug prune better? I tried using --dry-run and --json arguments but they don’t say why the module is being removed.

Any tips to help me figure out why my package is being removed?


I should also mention one work around to prevent prune from removing my local package was to basically modify the app’s package.json -> dependency from file:../ to ^1.0.0. Making it a semver number instead of the file: prevented npm from pruning it.

It works but its not ideal. I’d like to know what I’m doing wrong or if its a bug.