Search code examples
node.jswindowsmacosaccess-rights

Access rights for node_modules folder at MacOS/Linux and Windows


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?


Solution

  • 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.

    1. npm install yarn
    2. Inside your project folder in a cmd or a terminal just type yarn
      -Yarn will start resolving your packages.
    3. 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

    4. A .yarnrc file will be created in your home directory (macOS => ~/.yarnrc || windows => C:\{user}\.yarnrc).

    5. Move that file into your project to make it specific only to your project.

    6. 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.

    7. 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.

    8. 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..