npm prune removes local file path installs


(Seth Bertalotto) #1

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:

  • node -v: v10.7.0
  • npm -v: 6.4.0
  • os: Mac 10.13.6

Related issues:


(Kat Marchán) #2

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

So: file:foo/bar.


(Seth Bertalotto) #3

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


(Lars Willighagen) #4

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


(Seth Bertalotto) #5

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?


(Seth Bertalotto) #6

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.


(system) #7

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.