非sudo执行npm install报错求助(含两类错误日志)
Let's work through your npm install problems step by step—since you've already tried fixing permissions and reinstalling Node, we'll focus on clearing up cached data, fixing configuration issues, and ensuring your environment is consistent.
First, Let's Address the Initial E400 Bad Request Error
The E400 error when fetching TypeScript 2.6.2 usually points to a corrupted npm cache or misconfigured registry settings. Here's what to try:
Clear and Verify the npm Cache
Corrupted cache files often cause registry fetch errors. Run these commands to reset it:npm cache clean --force npm cache verifyIf that doesn't help, manually delete your user-level npm cache folder:
rm -rf ~/.npmCheck Your npm Registry Configuration
Ensure you're using the official npm registry (sometimes custom registries or typos cause 400 errors):npm config get registryIf the output isn't
https://registry.npmjs.org/, reset it:npm config set registry https://registry.npmjs.org/
Next, Fix the "Invalid Config Key" & "cb() Never Called!" Errors
After reinstalling Node, these new errors suggest corrupted configs or incompatible npm versions. Let's tackle them:
Remove Corrupted Local Dependency Files
Your project'snode_modulesorpackage-lock.jsonmight be damaged. Delete them and start fresh:rm -rf node_modules package-lock.jsonCheck for Malformed npm Configurations
The error mentions an invalid config keysingleuffer—this looks like a typo or accidental misconfiguration. List all your npm settings to spot odd entries:npm config listIf you see
singleufferor any other unrecognized keys, delete them:npm config delete singleufferFix Project Directory Permissions
Even if you fixed Node permissions, your project folder might still have root-owned files from previous sudo runs. Reset ownership to your user:sudo chown -R $USER:$USER /home/david/Dev/Projects/MobileInfoApp/LHMobileAppUpgrade npm to a Version Compatible with Node 8.11.2
Node 8.11.2 works best with npm 5.10.0 (the latest stable for that Node major version). Upgrade it globally (no sudo needed if you installed Node correctly for your user):npm install -g npm@5.10.0Consider Using nvm for Better Environment Management
If permission issues keep popping up, using Node Version Manager (nvm) eliminates the need for sudo entirely by installing Node/npm in your user directory. Once nvm is set up, run:nvm install 8.11.2 nvm use 8.11.2This will give you a clean, user-owned Node/npm environment.
Final Step: Re-Run npm Install
After completing the above steps, go back to your project directory and run:
npm install
This should work without sudo now.
内容的提问来源于stack exchange,提问作者daviedave

