Ubuntu系统中npm安装Firebase CLI失败及升级Node后新错误求助
Hey there, let's work through these Firebase CLI installation issues step by step—both the initial rollbackFailedOptional error and the new fetchMetadata : sill resolveWithNewModule problem after upgrading Node.js.
1. Fixing the rollbackFailedOptional Error (Node 8.9.4 / npm 5.6.0)
This error usually stems from corrupted npm cache, permission issues, or compatibility gaps between older Node/npm versions and Firebase Tools. Even though you've upgraded Node, here's how you'd fix it if you ever need to revert or hit this again:
- Clear the npm cache forcefully:
npm cache clean --force - Uninstall any partial or broken Firebase Tools installation:
npm uninstall -g firebase-tools - Reinstall with elevated permissions and the
--unsafe-permflag (critical for global installs on Ubuntu, as npm switches to a non-root user for script execution by default):sudo npm install -g firebase-tools --unsafe-perm
2. Fixing the fetchMetadata : sill resolveWithNewModule Error (Node 9.5.0)
This error means npm is getting stuck trying to resolve package metadata. It's almost always related to cache issues or network problems. Try these solutions in order:
Option 1: Wipe Cache and Reinstall
- Clear the npm cache again (sometimes the first clean doesn't get everything):
npm cache clean --force - Delete the entire npm cache directory to ensure no leftover corrupted data:
rm -rf ~/.npm - Reinstall Firebase Tools with verbose logging to track progress (helpful if it gets stuck again):
sudo npm install -g firebase-tools --unsafe-perm --verbose
Option 2: Use NVM for Better Node Version Management (Recommended Long-Term Fix)
Installing Node via Ubuntu's system package manager often leads to permission and compatibility headaches. NVM (Node Version Manager) lets you easily switch Node versions without sudo issues:
- Install NVM with the official script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - Refresh your terminal session to activate NVM (or run this command):
source ~/.bashrc - Install your desired Node version (9.5.0, or a more stable LTS version like 10.x since 9.x is non-LTS):
Or for an LTS release:nvm install 9.5.0nvm install --lts - Set it as your default Node version:
nvm alias default 9.5.0 - Now install Firebase Tools without sudo—no permission issues needed:
npm install -g firebase-tools
Option 3: Switch to a Domestic npm Registry (If Network is the Issue)
If npm can't reach the official registry due to network restrictions, switch to a faster domestic mirror:
npm config set registry https://registry.npmmirror.com
Then run the installation command again:
sudo npm install -g firebase-tools --unsafe-perm
Once you've tried these steps, verify the installation worked with:
firebase --version
内容的提问来源于stack exchange,提问作者Sony

