React Native报错:Can't find variable: regeneratorRuntime 求助
Hey there! That regeneratorRuntime error is super common when working with async/await or generator functions in React Native—usually it means your Babel setup isn’t handling these ES6+ features properly. Let’s walk through the fixes step by step:
First, here’s the error you’re seeing for reference:
Step 1: Install Required Babel Dependencies
You’ll need two packages to enable runtime transformation for generator functions:
- Run this command if you use npm:
npm install --save-dev @babel/plugin-transform-runtime npm install @babel/runtime - Or if you prefer yarn:
yarn add --dev @babel/plugin-transform-runtime yarn add @babel/runtime
Step 2: Update Your Babel Configuration
Open your project’s babel.config.js file (it should be in the root directory) and add the @babel/plugin-transform-runtime plugin to the plugins array. Your config should look something like this:
module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: ['@babel/plugin-transform-runtime'], };
Step 3: Clear Cache and Restart Your Project
React Native caches build assets aggressively, so we need to reset that to make sure the new Babel settings take effect:
- Stop any running React Native packager instances
- Run this command to clear the cache:
npx react-native start --reset-cache - Once the packager is running again, re-launch your app on the Android emulator:
npx react-native run-android
Bonus: Double-Check for Other Potential Issues
If the error still pops up, make sure:
- You’re using a supported version of React Native (most modern versions work with this fix, but if you’re on a very old release, you might need to update
@babel/coreas well) - You haven’t accidentally removed or modified the default
metro-react-native-babel-presetin your Babel config—it’s required for React Native to work properly
That should get rid of the regeneratorRuntime error and let your app run smoothly on the Android emulator!
内容的提问来源于stack exchange,提问作者Ogbonoko

