2

I have 4 modules inside node_modules folder where one of them is a custom module. In my package.json file, I have the other 3 modules specified as dependencies. So now when I do npm install node is removing that one custom module from node_modules folder because it is not listed in dependencies inside package.json file.

Is there anyway to keep this custom module without node deleting it when I do npm install? I've tried to include it in .npmignore file, but node is still deleting it.

baj9032
  • 2,414
  • 3
  • 22
  • 40
notQ
  • 229
  • 3
  • 14
  • 1
    possible duplicate of https://stackoverflow.com/questions/15806241/how-to-specify-local-modules-as-npm-package-dependencies. – Aagam Jain Sep 17 '18 at 13:05

1 Answers1

2

Put your custom module to another directory outside the node_modules and add it to your package.json as a file reference.

"dependencies": {
    "custom-module": "file:custom-module"
    ...

Then you can run npm install and it will sort out your node_modules right.

Sami Hult
  • 3,052
  • 1
  • 12
  • 17
  • How should I then specify the path for that module which now lies inside another folder? I put in it a folder name called server and use ***file:server/custom-module***, but node says it cannot find the module. – notQ Sep 17 '18 at 13:06
  • You can let `npm` to figure out the path for you: `npm install --save ../path-to/my-local-repo` – Sami Hult Sep 17 '18 at 13:08
  • This completely messed up with git :) It seems like Git has problem with symlink folder. Not just git, but Sublime Text too. – notQ Sep 17 '18 at 13:34
  • Have your `node_modules` in `.gitignore`. They are meant to be fetched using `npm install`! – Sami Hult Sep 17 '18 at 13:41