8

I have a npm dependency installed from a local path, which in turn has a few dependencies of its own. As I understand it, in this case npm just copies the contents of the local folder under node_modules. Is there any way to make it run npm install on the package folder before copying it?

Orgrim
  • 357
  • 1
  • 5
  • 13
  • Does this answer your question? [how to specify local modules as npm package dependencies](https://stackoverflow.com/questions/15806241/how-to-specify-local-modules-as-npm-package-dependencies) – Inigo May 22 '20 at 17:10

1 Answers1

4

npm install /path/to/foo simply copies from the specified path into your local package's node_modules folder. If this is what you meant by "installed from a local path", then that was the wrong thing to do if you want to make sure that npm update and npm install on your package would (a) automatically get the latest code from that path and (b) update/install the dependencies of the package at that path.

To accomplish (a) and (b), you can add that local dependency to your package.json's dependencies or devDependencies (supported by npm since 2.0). For example:

"dependencies": {
  "foo": "file:/path/to/foo"
}

After doing the above, npm update or npm install will treat that local dependency in the same way as any other dependency.

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • I had already saved the dependency on the package.json. The issue I was having was with babel not being found when run on the prepublish hook. moving that to install solved the problem. – Orgrim Nov 23 '16 at 22:52
  • 5
    my dependency frequently changes, is there way to update the repository also? even I have incremented version of dependency in dependency package.json and rerun the npm update, local dependecny update is not getting reflected in original project. – vishal-mote Jan 20 '17 at 07:34
  • @vishal-mote Did you ever figure out a solution to this? – Jase Jul 11 '21 at 09:11
  • Nope, unable to figure it out. – vishal-mote Aug 05 '21 at 09:55