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

Expo运行代码找不到babel-plugin-react-native-dotenv等模块求解决方案

问题原因

错误是因为你错误将babel-preset-expo(Babel预设)放到了plugins数组中,Babel加载插件时会自动添加babel-plugin-前缀,因此会尝试查找不存在的babel-plugin-babel-preset-expo包,触发报错。此前的Cannot find module 'babel-plugin-react-native-dotenv'报错,一般是依赖未正确安装或者配置字段错误导致。

可行解决步骤
  • 第一步:修正babel.config.js配置,拆分预设(presets)和插件(plugins)字段,修改后配置如下:
module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['module:react-native-dotenv'],
  }
}
  • 第二步:确认已正确安装react-native-dotenv开发依赖,执行对应安装命令:
    npm安装:npm install react-native-dotenv --save-dev
    yarn安装:yarn add react-native-dotenv --dev
  • 第三步:清理Expo缓存后重启服务,执行命令:
    npx expo start --clear

内容的提问来源于stack exchange,提问作者Rogue

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 18:54:00