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

MacOS Monterey运行ng new创建Angular项目mkdir node_modules权限被拒绝如何解决

修复步骤

  • 修正目标目录权限,使用绝对路径避免相对路径定位错误:
    sudo chown -R franfonse:staff /Users/franfonse/Desktop/Programming
    
  • 修复npm全局缓存目录的权限,清理残留缓存:
    sudo chown -R franfonse:staff ~/.npm
    npm cache clean --force
    
  • 不要使用sudo执行ng new创建项目的命令,执行命令时确认当前工作目录为/Users/franfonse/Desktop/Programming,再重新运行创建命令:
    cd /Users/franfonse/Desktop/Programming
    ng new my-app
    
  • 如果上述操作后仍报错,可手动创建项目目录后再初始化,规避目录自动创建的权限冲突:
    mkdir /Users/franfonse/Desktop/Programming/my-app
    cd /Users/franfonse/Desktop/Programming/my-app
    ng new my-app --directory ./
    
  • 若仍存在权限问题,可将npm全局包安装路径修改为当前用户目录下,避免系统级权限限制:
    mkdir ~/.npm-global
    npm config set prefix '~/.npm-global'
    # 若使用zsh执行以下命令
    echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.zshrc
    source ~/.zshrc
    # 若使用bash执行以下命令
    # echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.bash_profile
    # source ~/.bash_profile
    
    # 重新安装Angular CLI
    npm install -g @angular/cli
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 15:24:00