Angular项目执行ng new后npm install失败,报错ENOENT求助
Hey there, I feel your pain—this ENOENT rename error when running npm install for an Angular project is such a frustrating roadblock, especially after you’ve already tried all the usual fixes. Let’s dive into some targeted solutions that might get you past this:
Clean up residual files manually
The error points to a failed rename of thetypescriptfolder, which often means there’s a corrupted or leftover file blocking the process. Follow these steps:- Delete your entire
node_modulesfolder - Delete
package-lock.json(it’ll get regenerated automatically later) - Navigate to
D:\Project\FrontEnd\node_modules\@angular-devkit\build-optimizer\node_modulesand check for a.typescript.DELETEfile—if it exists, delete it manually - Run
npm installagain
- Delete your entire
Shorten your project path
Windows has a default maximum path length limit, and your current directory path might be hitting that threshold. Try moving your project to a shorter location, likeD:\Proj\AngularAppinstead ofD:\Project\FrontEnd, then re-runnpm install.Use
npm ciinstead ofnpm installnpm ciinstalls dependencies strictly from thepackage-lock.jsonfile, skipping any cached or partial installs that could be causing conflicts. Run this command:npm ci(Note: This will automatically delete your
node_modulesfolder before starting the fresh install)Verify folder permissions
Make sure your user account has full read/write access to your project folder. Right-click the folder → Properties → Security tab → Confirm your user has "Full Control" permissions. If not, add this permission and try the install again.Upgrade Node.js and npm
Your current versions (Node v8.10.0, npm 5.6.0) are quite outdated, and newer Angular CLI versions often have compatibility issues with older runtime environments. Try upgrading to a LTS version of Node.js (like v16.x or v18.x)—this will come with a newer, more stable npm version. After upgrading:- Uninstall the global Angular CLI:
npm uninstall -g @angular/cli - Clear the npm cache:
npm cache clean --force - Reinstall the latest Angular CLI:
npm install -g @angular/cli - Create a new project and run
npm installagain
- Uninstall the global Angular CLI:
Switch to a mirror npm registry
Sometimes network glitches or registry inconsistencies can cause partial, corrupted downloads. Try using a mirror registry like npmmirror:npm install --registry=https://registry.npmmirror.com
内容的提问来源于stack exchange,提问作者Nicholas Heath

