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

React Native安卓打包失败:原生运行时不含Node标准库

React Native Expo 图片选择器教程第4步打包失败问题

我是应用开发新手,此前能正常运行React Native安卓应用,但跟着Expo官网的图片选择器教程进行到第4步、修改代码后,应用无法运行。

PowerShell中收到如下错误:

Android Bundling failed 3813ms The package at "node_modules\@expo\config-plugins\build\android\EasBuild.js" attempted to import the Node standard library module "fs". It failed because the native React runtime does not include the Node standard library.

手机端Expo Go应用显示500错误代码。我尝试过Stack Overflow及GitHub相关问题的解决方案,但均未成功,其中部分GitHub评论难以理解,且担心修改过多无法回退。

补充说明:将修改后的ImageViewer.js代码改回原版后,应用可在手机上正常运行。

修改后的ImageViewer.js

import { Styles } from '@expo/config-plugins/build/android';
import { StyleSheet, Image } from 'react-native';

export default function ImageViewer({ placeholderImageSource, selectedImage }) {
  const imageSource = selectedImage !== null
  ? {uri: selectedImage }
  : placeholderImageSource;
  return <Image source={imageSource} style={styles.image} />;
}

const styles = StyleSheet.create({
  image: {
    width: 320,
    height: 440,
    borderRadius: 18,
  },
});

原版originalImageViewer.js

import { StyleSheet, Image } from 'react-native';

export default function ImageViewer({ placeholderImageSource }) {
  return (
    <Image source={placeholderImageSource} style={styles.image} />
  );
}

const styles = StyleSheet.create({
  image: {
    width: 320,
    height: 440,
    borderRadius: 18,
  },
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 16:30:58