使用npm安装Angular CLI遇EPERM错误(errno-4048)求助
Hey there, let's tackle this permission issue you're hitting when trying to install Angular CLI globally. Based on your details (Windows 10, Node v7.7.2, npm 4.1.2), here are the actionable steps to resolve the EPERM error and address that sass-loader warning:
1. Run Your Terminal as Administrator First
The EPERM error about renaming the temporary package.json file is almost always tied to insufficient system-level permissions. Even if you changed the npm global path, if your terminal isn't running as admin, Windows might block the file operations.
- How to do it: Go to the Start menu, search for Command Prompt or PowerShell, right-click it, and select Run as administrator.
- Then re-run the installation command:
npm install -g @angular/cli
2. Verify Your npm Global Path Configuration
You mentioned changing the global path to D:\node_modules, but let's double-check it's set up correctly (sometimes the prefix path needs to be a parent directory, not the node_modules folder itself):
- Check your current prefix setting:
npm config get prefix - If it's not pointing to a dedicated global folder (like
D:\node_global), update it along with the cache directory to avoid system disk permissions:npm config set prefix "D:\node_global" npm config set cache "D:\node_cache" - Don't forget to add
D:\node_globalto your System PATH environment variable. This ensures your system can find thengcommand after installation.
3. Clear npm Cache to Fix Temporary File Issues
Corrupted cache can sometimes cause file renaming errors. Let's wipe it clean before re-trying the install:
npm cache clean --force
4. Address the sass-loader Dependency Warning
That warning is likely because your Node.js version (v7.7.2) is quite outdated—newer versions of sass-loader don't support such old Node releases. Here's how to handle it:
- First, get Angular CLI installed using the steps above. Once that's done, when creating new projects, you can specify a compatible sass-loader version in your project's
package.json. - Pro tip: Consider upgrading Node.js to a supported LTS version (like 16.x or 18.x) using a version manager like nvm-windows. This will eliminate most compatibility warnings and make future package installations smoother.
5. If All Else Fails: Uninstall and Reinstall Node.js
If the permission issues persist, a clean reinstall of Node.js (using the official installer, run as admin) can reset any misconfigured permissions. Make sure to delete the old npm global/cache folders before reinstalling.
内容的提问来源于stack exchange,提问作者technoJ

