You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
通常,本地启服务器要监听 1024 以内(不包括)端口的时候,需要 root 权限(sudo);但是如果你是 Mac 用户,且系统是 macOS Mojave 之后,就不需要 root。因为这个版本之后 macOS 就没有这个限制了。
但是如果监听时还同时指定了 Host 或 IP(非 0.0.0.0),则又需要 root 了;所以 Mac 上完整的限制是:监听 1024 以内端口,且指定监听 Host 或 IP,则需要 root 权限。
而 vite 的
server.host
默认配置是 127.0.0.1,指定了 IP,所以如果没有改默认配置,且监听特权端口,你还是需要 sudo 以使用 root 权限。但是,如果你使用的是 npm,且决心要 sudo 了,那么很可能还是碰到 EAccess 的问题。这是 npm 的一个 BUG:如果你在某目录下执行
sudo npm run xxx
,npm 并不会以 root 权限执行 xxx,而是以该目录所有者的权限去执行。所以你会在网上看到一些奇怪的解决方案是把项目目录的 owner 设置为 root。我不能确定这个 BUG 什么时候开始的,但是目前最新版本的 npm(8.3.0)仍然存在这个问题。虽然已经修复但是仍然没有发布。所以汇总下什么时候需要 sudo(以下建议仅针对 macOS Mojave 用户):
Beta Was this translation helpful? Give feedback.
All reactions