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

Angular项目构建报错:未依赖@angular/core及npm安装权限问题

Fixing "You seem to not be depending on @angular/core" & EACCES Permission Errors

Hey there, let's work through these two linked issues one by one—they’re usually fixable with a few straightforward steps.

First: Resolve the EACCES Permission Denied Error

That permission error pops up when npm tries to modify files it doesn’t have access to, often because you previously used sudo to install packages (which messes up file ownership) or your global npm directory is locked down. Here’s what to do:

This avoids needing sudo entirely going forward:

  • Create a dedicated global npm directory in your user folder:
    mkdir -p ~/.npm-global
    
  • Configure npm to use this directory:
    npm config set prefix '~/.npm-global'
    
  • Add this directory to your shell’s PATH (update .bashrc, .zshrc, or whichever config your shell uses):
    echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.bashrc
    
  • Reload your shell config to apply the change:
    source ~/.bashrc
    

Option 2: Fix Project Directory Ownership

If the issue is specific to your project’s node_modules folder:

sudo chown -R $USER:$USER /path/to/your/angular-project

While this will install the package, it can cause more permission issues later:

sudo npm install @angular/core --save

Second: Fix the "@angular/core" Dependency Error

Once permissions are sorted, let’s tackle the original build error. This usually means either the dependency is missing, or your project’s cache/lock files are corrupted.

  1. Check your package.json
    Open your project’s package.json and confirm @angular/core is listed under dependencies. If it’s missing, install it with:

    npm install @angular/core --save
    
  2. Clean Corrupted Cache & Dependencies
    If @angular/core is already in package.json, the issue might be corrupted files:

    • Delete the node_modules folder and lock file:
      rm -rf node_modules package-lock.json
      
    • Reinstall all dependencies:
      npm install
      
  3. Clear Angular CLI Cache
    Sometimes the Angular CLI cache causes weird dependency issues:

    ng cache clean --all
    
  4. Double-Check Build Command
    Make sure your build command’s flags are correct—specifically, ensure --output-path and --base-href point to valid paths (no typos or invalid characters).

After trying these steps, re-run your build command:

ng build --environment=prod --aot=false --output-path="..." --base-href="..."

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:34:56