Reputation: 1102
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:
To create symlinks on windows, the process needs administrator permissions, or developer mode on windows 10. I'd not count either as "out of the box", a build needing administrator or special OS-flags is a non-solution. This means neither npm install <folder>
nor npm link
work, as both create symlinks.
An alternative is creating a tarball, and installing that. First of all, this introduces an unnecessary copy, which complicates making changes to the package. Secondly, this tarball needs to be created, before installation, but preinstall
for mythical reasons is still not done first. Updating fails, as it tries to resolve the file, before preinstall
generated it.
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
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