node.js - 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?
解决方案
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
- Inside your project folder in a cmd or a terminal just type
yarn
-Yarn will start resolving your packages. 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 innode_modules
folder and ayarn.lock
file. Also note that in the home directory under the foldernpm-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..
推荐阅读
- swift - 为 tableviewcell 设置图像会减慢 Swift 中的滚动速度
- python - python中href url中的正则表达式数字
- java - Spring boot jquery 和 bootstrap 导入
- c# - .net core api 为每个请求返回客户端 index.html 文件
- lambda - Kong + Lambda Plugin - 如何启用重试?
- asp.net - 在 MVC 中通过 Excel 加载器上传时等待操作超时
- apache - 设置虚拟主机以重定向到多个 Web 服务器 (apache)
- oracle - 如何将 OBIEE 的 FORECAST 功能与我的日历维度一起使用?
- asp.net-mvc - 断开连接后如何正确重新连接signalR
- database - 检查函数依赖是否在闭包中