Doofus
Doofus

Reputation: 1102

Npm install local directory on windows out-of-the-box

I have a package which resides in a subfolder of another package (or anywhere locally), and the parent package now needs to install it:

📁main
 ├──📁node_modules
 ├──📁otherProject
 │   ├──📁node_modules
 │   ├──index.js
 │   └──package.json
 ├──package.json
 └──something.anything

The files (apart from node_modules and other common items) are from version control. Is there a way to do this on windows 7/8/10 without elevated permissions, that works "out of the box"?

On linux this would be a simple npm install ./otherProject.

While not too relevant, i'll add that this is a custom eslint plugin. Maybe someone has a tip that solves the specific situation, but isn't generalizable.


A short summary of the issues:

I don't see any of the solutions in e.g. this question to apply. This answer helped with the tarball approach, which is also now stuck. I hope i am just misunderstanding something, or making a simple mistake.

Upvotes: 0

Views: 570

Answers (1)

jtwalters
jtwalters

Reputation: 1134

I think is a bad practice to reference a module from another folder to production.

I recommend you have a different folder for each project:

📁main
 ├──📁mainProject
 │   ├──📁node_modules
 │   ├──package.json
 │   └──something.anything
 ├──📁otherProject
 │   ├──📁node_modules
 │   ├──index.js
 │   └──package.json
 └──otherProject-1.0.0.tgz // This file is created by node...

So first you package the other project and install it in your main project

main> npm pack otherProject
main> cd mainProject
main\mainProject> npm install --save ../otherProject-1.0.0.tgz

You would have more control and your solution will be cleaner.

NOTE: If you don't change the version in package.json in otherProject when you make any change and pack it you will have the previous version.

In case you want to keep the version in package.json you could clean the cache of npm with:

npm cache clean --force

Upvotes: 1

Related Questions