执行ng build报错未依赖@angular/core,npm install遇EEXIST错误求助
Let's break down and fix these two issues one by one—starting with the blocking npm error first, then addressing the missing @angular/core dependency.
1. Resolve the npm ERR! code EEXIST Error
This error pops up because the ng command file at /usr/local/bin/ng already exists, and npm can't overwrite it during the global CLI installation. Here's how to clear this conflict:
- First, delete the existing
ngfile to make space for the fresh installation:sudo rm /usr/local/bin/ng - Next, clear npm's cache to get rid of any corrupted or outdated cached files that might cause issues:
npm cache clean --force - Since your Node.js version is v9.10.1 (which is older), you'll need a compatible Angular CLI version—newer CLI releases won't play nice with Node v9. Install Angular CLI 7.x (the latest stable version that supports Node v9):
npm install -g @angular/cli@7.3.9 - Verify the installation worked by checking the CLI version:
ng --version
2. Fix the "You seem to not be depending on '@angular/core'" Error
This error means your project's local dependencies are either missing, corrupted, or @angular/core isn't properly listed in your package.json. Let's fix that:
- Navigate to your project's root directory first.
- Delete the local
node_modulesfolder andpackage-lock.jsonfile to wipe out any corrupted dependency data:rm -rf node_modules package-lock.json - Reinstall all local project dependencies from scratch:
npm install - If
@angular/corestill doesn't show up in yourpackage.jsonafter reinstalling, manually add it (match the version to your Angular CLI—for CLI 7.x, use Angular core 7.x):npm install @angular/core@7.2.16 --save - Finally, try building your project again:
ng build
A quick heads-up: Node.js v9 is no longer supported, so if you can spare the time, upgrading to a newer LTS version (like Node 14 or 16) will help avoid future compatibility headaches. But the steps above should get your current setup working smoothly.
内容的提问来源于stack exchange,提问作者Floriane

