I'm developing some nodeJS applications on a mac machine. For testing purpose I'm using Parallels to get a virtual windows machine (win 10).
If I'm running npm install
for a project on my mac, I can't run the project on the windows machine, as I'm getting an access denied
error for the node_modules folder.
So I deleted the folder an run npm install
on the windows machine. With that I can run the app. But then on my mac machine I do get e.g. sh: /Users/project/node_modules/.bin/nodemon: Permission denied
.
What can I do to set the correct access rights to the node_modules directory to get the app running on both OS?
That is because the binaries (.bin) compiled in macOS need not necessarily work with windows too. For your scenario, use YARN. Because YARN offers offline install.
Reference link: https://yarnpkg.com/blog/2016/11/24/offline-mirror/
In either of your systems install YARN.
npm install yarn
yarn
Once done, create a .yarnrc
file by executing the following commands (same for both windows and macOS).
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
yarn config set yarn-offline-mirror-pruning true
A .yarnrc
file will be created in your home directory (macOS => ~/.yarnrc || windows => C:\{user}\.yarnrc
).
Move that file into your project to make it specific only to your project.
Now do a yarn install
-> Results in node_modules
folder and a yarn.lock
file. Also note that in the home directory under the folder npm-packages-offline-cache
you will have all the dependencies in tarball format.
All you have to do is Commit this tarball directory and the yarn.lock to a repository common to both the environments, setup yarn in other environment by repeating the same 1-5 steps.
Finally run yarn install -offline, you will have the dependencies loaded.
Long story, Short! You can't just copy paste node_modules and get it working between windows and unix.
Hope it helps you..