You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native报错:Can't find variable: regeneratorRuntime 求助

Fixing "Can't find variable: regeneratorRuntime" in React Native (Android Emulator)

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:
Can't find variable: regeneratorRuntime error screenshot

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:

  1. Stop any running React Native packager instances
  2. Run this command to clear the cache:
    npx react-native start --reset-cache
    
  3. 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/core as well)
  • You haven’t accidentally removed or modified the default metro-react-native-babel-preset in 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:55:22