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

Expo SDK 47升级至48后iOS端出现Buffer不存在错误求助

Expo SDK 47升级至48后iOS启动报错:ReferenceError: Property 'Buffer' doesn't exist, js engine: hermes

将Expo SDK从47版本升级至48版本后,Android和iOS项目均可成功构建,但启动iOS应用时会出现以下错误:

ReferenceError: Property 'Buffer' doesn't exist, js engine: hermes

无法定位问题根源,已查找多个平台解决方案未果,以下是完整的package.json内容:

{"scripts": {"start": "expo start --dev-client", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", "eject": "expo eject"}, "dependencies": {"@expo-google-fonts/nunito": "^0.2.0", "@expo/dev-server": "^0.2.2", "@expo/vector-icons": "^13.0.0", "@native-html/table-plugin": "^5.3.1", "@react-native-async-storage/async-storage": "1.17.11", "@react-native-community/netinfo": "9.3.7", "@react-navigation/bottom-tabs": "^6.0.9", "@react-navigation/elements": "^1.2.1", "@react-navigation/native": "^6.0.6", "@react-navigation/native-stack": "^6.2.5", "@react-navigation/stack": "^6.0.11", "@types/react-native-loading-spinner-overlay": "^0.5.3", "@types/redux-logger": "^3.0.9", "@types/styled-components-react-native": "^5.1.3", "axios": "^0.24.0", "axios-hooks": "^3.0.0", "expo": "~48.0.18", "expo-apple-authentication": "~6.0.1", "expo-application": "~5.1.1", "expo-auth-session": "~4.0.3", "expo-clipboard": "~4.1.2", "expo-constants": "~14.2.1", "expo-dev-client": "~2.2.1", "expo-device": "~5.2.1", "expo-font": "~11.1.1", "expo-in-app-purchases": "~14.1.1", "expo-linear-gradient": "~12.1.2", "expo-linking": "~4.0.1", "expo-notifications": "~0.18.1", "expo-random": "~13.1.1", "expo-splash-screen": "~0.18.2", "expo-status-bar": "~1.4.2", "expo-store-review": "~6.2.1", "expo-tracking-transparency": "~3.0.1", "expo-updates": "~0.16.4", "formik": "^2.2.9", "install": "^0.13.0", "laravel-echo": "^1.11.3", "moment": "^2.29.4", "moment-timezone": "^0.5.34", "moti": "^0.17.1", "pusher-js": "^7.0.6", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.71.8", "react-native-autolink": "^4.0.0", "react-native-chart-kit": "^6.12.0", "react-native-device-info": "^8.7.0", "react-native-draggable-dynamic-flatlist": "^1.0.4", "react-native-draggable-flatlist": "^3.0.5", "react-native-elements": "^3.4.2", "react-native-fbsdk-next": "^11.1.0", "react-native-flash-message": "^0.4.1", "react-native-gesture-handler": "~2.9.0", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-keyboard-aware-view": "^0.0.14", "react-native-loading-spinner-overlay": "^2.0.0", "react-native-modal": "13.0.1", "react-native-modalize": "^2.0.13", "react-native-pager-view": "6.1.2", "react-native-paper": "^4.11.1", "react-native-pulse": "^1.0.7", "react-native-purchases": "^5.5.0", "react-native-reanimated": "~2.14.4", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.20.0", "react-native-select-dropdown": "^1.7.0", "react-native-svg": "13.4.0", "react-native-swipeable-item": "^2.0.8", "react-native-tab-view": "^3.1.1", "react-native-web": "~0.18.7", "react-native-webview": "11.26.0", "react-redux": "^7.2.6", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "redux-thunk": "^2.4.1", "socket.io-client": "^4.4.1", "styled-components": "^5.3.3", "yup": "^0.32.11"}, "devDependencies": {"@babel/core": "^7.19.3", "@types/react": "~18.0.24", "@types/react-native": "~0.70.6", "@types/react-redux": "^7.1.21", "typescript": "^4.6.3"}, "resolutions": {"@types/react": "18.0.24", "@types/react-dom": "18.0.11"}, "private": true, "version": "1.0.0"}
解决方案

这个错误是因为Hermes引擎默认不包含Node.js的Buffer模块,你的项目里像pusher-js、laravel-echo这类依赖会用到它。按以下步骤处理:

  • 安装buffer polyfill包
    在项目根目录执行命令:

    npm install buffer
    # 或用yarn
    yarn add buffer
    
  • 配置metro.config.js添加polyfill
    没有该文件就新建一个,添加以下配置:

    const { getDefaultConfig } = require('expo/metro-config');
    
    const config = getDefaultConfig(__dirname);
    
    config.resolver.extraNodeModules = {
      buffer: require.resolve('buffer'),
    };
    
    config.transformer.babelTransformerPath = require.resolve('react-native-preset-expo');
    
    module.exports = config;
    
  • 在入口文件全局注入Buffer
    打开项目入口文件(比如App.js或index.js),在最顶部添加:

    import { Buffer } from 'buffer';
    global.Buffer = Buffer;
    
  • 清除缓存重新构建
    执行命令清除缓存后重新运行iOS项目:

    npx expo start --clear
    # 之后运行
    npx expo run:ios
    

如果以上方法没用,还可以检查:

  • 把pusher-js升级到最新版本,确认是否兼容Expo 48
  • 通过Hermes调试工具定位调用栈,排查是否有其他依赖在隐式使用Buffer

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 13:56:59