1

Many of the same questions have been asked before link, but none give a solid answer or are very outdated, so just asking again.

I have a package.json with a local npm module:

{
  "dependencies": {
    "local_module": "file:..pathtomodule"
  }
}

when i run npm i for the host package, the local module is installed, but modules from the local_module are not installed. So I have to run a separate npm i for the local_module.

What am i doing wrong?? isn't it just a module??

p.s. why am i getting minus for the question? please explain so I can improve

thanks in advance

DutchKevv
  • 1,451
  • 1
  • 18
  • 36

2 Answers2

1

From my understanding of npm, the dependencies for the local modules should be installed from that specific modules package.json. All dependencies listed in the local module will be installed from a "npm i" as new versions of npm install peer dependencies automatically. You could also just publish the local module and install it using npm, I haven't heard of local modules being used in package.json dependencies. I'm also quite new to node and npm.

Example: note how the morgan module has a package.json file and has further dependencies. These would be installed along with morgan with "npm i morgan". enter image description here

JavanPoirier
  • 397
  • 2
  • 8
  • thanks for your quick reply! Thats exactly the thing that confuses me.. A 'normal' npm module like morgan also has (sub) dependencies that are installed when you do a 'npm install' from the host package.json (not defining a specific module to install, but just 'all modules'.. So why is a local module treated differently and sub deps are not installed automatically ? It seems counter effective for using local modules.. – DutchKevv May 09 '18 at 17:32
  • Im not to sure about local modules. Does your local module have a package.json with its own list of dependencies? If so I can see why "npm i" would not work. Maybe try "npm i -install-peers", where the dependencies are a peer of the module? – JavanPoirier May 09 '18 at 17:37
  • a good one i try install-peers (narf! install-peers is removed since npm 3:()! Yes the sub-module has a package.json and if I run 'npm i' in the folder where the sub-module files are, it works.. So that makes it even stranger.. Its like the local_module is not using the same node_modules folder as its parent.. I also tried a fresh git clone etc to be sure there are no npm link left over etc – DutchKevv May 09 '18 at 17:39
  • I know from older versions of npm, child node_modules where a thing. each module had its own node_modules folder. They took that out as it made things confusing. All peer dependencies should be in the single project node_modules folder. – JavanPoirier May 09 '18 at 17:43
  • p.s. the github repo is public so just share it here.. https://github.com/DutchKevv/TradeJS | The shared/modules/coinpush contains the local module, and the 'server-gateway' imports it.. Maybe you/someone sees a screw up in the blink of an eye..... (oh and i'm working on development branch...) – DutchKevv May 09 '18 at 17:50
  • 1
    You appear to be WAY more experienced than me my friend. Sorry I couldn't be of any more assistance. I'll keep looking... – JavanPoirier May 09 '18 at 18:05
  • haha noooo we all have our experiences! ;) Many thanks for brainstorming with me.. There is just something i totally misunderstand and i'm almost ready to say I also don't understand shit of it :p much love and kudo's for helping me – DutchKevv May 09 '18 at 18:24
1

What I use to do in that case is to "force" dependencies to be "npm installed" using preinstall script in the root module:

   {
      "dependencies": {
        "local_module": "file:..pathtomodule"
      },
      "scripts": {
        "preinstall": "npm install ..pathtomodule"
      }
    }