Expo中使用react-native-reanimated插件报错,请求解决方案
解决Expo中React抽屉导航+react-native-reanimated的Babel错误
问题重现
使用React抽屉导航并集成react-native-reanimated时,Expo抛出错误:
Export namespace should be first transformed by
@babel/plugin-proposal-export-namespace-from.
解决方案
1. 安装必要的Babel插件
首先安装处理命名空间导出所需的依赖插件:
npm install --save-dev @babel/plugin-proposal-export-namespace-from # 或使用yarn yarn add --dev @babel/plugin-proposal-export-namespace-from
2. 调整Babel配置顺序
在项目根目录的babel.config.js文件中(无则新建),确保@babel/plugin-proposal-export-namespace-from放在react-native-reanimated/plugin之前——Reanimated插件依赖前者先完成转换:
module.exports = function(api) { api.cache(true); return { presets: ['babel-preset-expo'], plugins: [ '@babel/plugin-proposal-export-namespace-from', 'react-native-reanimated/plugin', ], }; };
注:app.json中的react-native-reanimated/plugin配置可保留,但Babel配置必须明确添加上述两个插件并保证顺序正确。
3. 清除缓存并重启Expo服务
Expo编译缓存可能残留旧配置,执行以下命令清除缓存并重启服务:
npx expo start --clear
4. 验证依赖版本兼容性
确保react-native-reanimated版本与你的Expo SDK、React Navigation版本匹配:
- Reanimated 3.x 需要 Expo SDK 49 及以上版本
- 可通过以下命令同步安装兼容版本:
npx expo install react-native-reanimated
内容的提问来源于stack exchange,提问作者Yefim Blokh
相关产品推荐
相关产品推荐

