修改Android版本信息后React Native Metro报错‘Failed to construct transformer’求助
Hey there, sorry to hear you ran into this frustrating hiccup after tweaking your Android version code/name. The good news is this error almost never ties directly to those version changes—it’s just a timing coincidence. Let’s walk through some tried-and-true fixes to get your Metro server back up and running smoothly:
Reset Metro’s cache completely
Corrupted cache is the #1 culprit here. Skip the basic restart and run this command to wipe Metro’s cache entirely:npx react-native start --reset-cacheThis forces Metro to rebuild all its transformers from scratch, which often resolves the "call retries exceeded" error right away.
Free up Metro’s default port (8081)
Sometimes a leftover process or another app is hogging the port Metro uses. Here’s how to kill it:- On Windows:
netstat -ano | findstr :8081 taskkill /PID <your-process-ID> /F - On Mac/Linux:
lsof -ti:8081 | xargs kill -9
After freeing the port, restart Metro with
npx react-native start.- On Windows:
Clean Android build artifacts
Since you modified Android config files, leftover build cache might be causing unexpected conflicts. Head into yourandroidfolder and run:- Windows:
gradlew clean - Mac/Linux:
./gradlew clean
Then return to your project root and restart your app.
- Windows:
Check Node.js version compatibility
Thejest-workererror often pops up if your Node.js version clashes with your React Native/Metro setup. Use a version manager likenvmto switch to a stable, recommended version (16.x or 18.x work for most recent RN projects):nvm use 18 rm -rf node_modules yarn.lock yarn installResolve dependency lock file conflicts
Mismatched versions ofjest-workerin your lock file can cause hidden issues. Back up youryarn.lockorpackage-lock.json, delete it, then reinstall dependencies fresh:rm yarn.lock yarn install
If none of these work, try deleting the hidden .metro-cache folder in your project root, then restart Metro again. Most folks fix this with the first or second step, so start there!
内容的提问来源于stack exchange,提问作者narutoobito

