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

安装@ngrx/store遇权限问题求助:sudo安装后依赖未生效

Fixes for @ngrx/store Installation Permission & Missing Package Issues

Hey there, let's work through this @ngrx/store installation problem step by step— I've dealt with similar npm permission headaches before, so these solutions should get you back on track:

1. Fix npm Permissions to Avoid Using sudo

The EACCES error pops up because npm is trying to write to a directory it doesn't have access to. Using sudo is a quick but risky fix here—it messes with file ownership and can cause more weird issues later. Let's set up a user-specific npm directory instead:

  • Create a global npm folder in your user directory:
    mkdir ~/.npm-global
    
  • Configure npm to use this new directory:
    npm config set prefix '~/.npm-global'
    
  • Add this directory to your shell's PATH (update the file for your shell—.bashrc for Bash, .zshrc for Zsh):
    echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.bashrc
    
  • Refresh your shell to apply the change right away:
    source ~/.bashrc
    

2. Repair Local Project File Ownership

If you ran sudo npm install earlier, your project files (like node_modules, package.json) might now be owned by root. That blocks npm from modifying them as your regular user, which explains why the package didn't show up even after "successful" sudo installs. Fix ownership with:

  • Navigate to your Angular project folder, then run:
    sudo chown -R $(whoami) ./node_modules
    sudo chown -R $(whoami) package.json package-lock.json
    

3. Install the @ngrx/store Version Compatible with Angular 5

Angular and @ngrx versions are tightly aligned—Angular 5 requires @ngrx/store 5.x (installing the latest version straight up will cause compatibility issues). Install the matching version explicitly:

npm install @ngrx/store@5.2.0 --save

4. Clear npm Cache (If Issues Persist)

Sometimes a corrupted cache can cause silent failures. Clear it with:

npm cache clean --force

Then re-run the install command from step 3.

Why sudo Didn't Work

When you use sudo, npm runs as the root user. This might install packages to a global directory instead of your project's node_modules. Plus, root ownership of package.json means npm can't update it when you switch back to your regular user—hence why the package never showed up there, even if the sudo command didn't throw errors.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:48:19