You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS High Sierra环境下Node.js服务器无法启动及权限问题求助

Fixing Node.js Server Startup & Permission Denied on macOS High Sierra

Hey there, let’s work through your Node.js server issue and that annoying permission error step by step.

First: Resolve the "Permission Denied" when deleting node_modules

The /usr/local/lib/node_modules directory is owned by root by default on macOS, which is why you can’t delete it with a regular rm command. Here are two reliable fixes:

  • Use sudo to temporarily gain root privileges:
    Run this command in iTerm, then enter your macOS user password (note: nothing will show on screen as you type—this is normal):
    sudo rm -rf /usr/local/lib/node_modules
    
  • Alternatively, take ownership of the directory first (so you won’t need sudo for future operations here):
    sudo chown -R $(whoami) /usr/local/lib/node_modules
    
    After running this, you can delete the directory with a regular rm -rf /usr/local/lib/node_modules command without permission issues.

Next: Troubleshoot Node.js Server Startup Failure

Deleting node_modules might fix dependency-related issues, but let’s cover other common causes too:

  • Verify Node.js is installed correctly:
    Run these commands to check if Node and npm are properly set up:

    node -v
    npm -v
    

    If either command doesn’t return a version number, you’ll need to reinstall Node.js (download the installer from the official site, or use a version manager like nvm for easier future management).

  • Check for startup errors:
    When you try to start your server, pay close attention to the error messages in iTerm. Common issues include:

    • Port conflicts (another app is using the port your server tries to listen on)
    • Syntax errors in your Node.js code
    • Missing dependencies (even after reinstalling, double-check that all required packages are listed in package.json)
  • Reinstall dependencies after deleting node_modules:
    Once you’ve removed the old node_modules folder, navigate to your project directory in iTerm and run:

    npm install
    

    This will rebuild all dependencies based on your package.json file.

内容的提问来源于stack exchange,提问作者rollback

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:04:17