【问题标题】:React Native archive error: Unable to find React Native files. Make sure "react-native" module is installed in your project dependenciesReact Native 存档错误:无法找到 React Native 文件。确保在您的项目依赖项中安装了“react-native”模块
【发布时间】:2026-01-24 19:30:02
【问题描述】:

我正在尝试归档使用 React Native 构建的(否则完美构建,在模拟器/设备上运行以进行调试)iOS 应用。

当我尝试在 Xcode 中存档时,它会正确编译和链接,但在尝试生成资产时会调用以下命令:

node '/Users/Can/Documents/Programming/React Native/REDACTED/node_modules/react-native/cli.js' bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/Can/Library/Developer/Xcode/DerivedData/REDACTED-eebdhuhscigvmvduljehleepetoi/Build/Intermediates.noindex/ArchiveIntermediates/REDACTED/BuildProductsPath/Release-iphoneos/REDACTED.app/main.jsbundle --assets-dest /Users/Can/Library/Developer/Xcode/DerivedData/REDACTED-eebdhuhscigvmvduljehleepetoi/Build/Intermediates.noindex/ArchiveIntermediates/REDACTED/BuildProductsPath/Release-iphoneos/REDACTED.app

失败并出现错误:

error Unable to find React Native files. Make sure "react-native" module is installed in your project dependencies.. Run CLI with --verbose flag for more details.

(在你问之前,是的react-native 显然安装在我的项目依赖项中)

当我手动调用那个确切的节点命令时,它会非常好地生成资产:

warning: the transform cache was reset.
Loading dependency graph, done.
info Writing bundle output to:, /Users/Can/Library/Developer/Xcode/DerivedData/REDACTED-eebdhuhscigvmvduljehleepetoi/Build/Intermediates.noindex/ArchiveIntermediates/REDACTED/BuildProductsPath/Release-iphoneos/REDACTED.app/main.jsbundle
info Done writing bundle output
info Copying 30 asset files
info Done copying assets

因此,我无法归档我的应用。它建议我使用 --verbose 标志运行 CLI,但我不知道在哪里添加标志,因为命令本身是从自动生成/复杂的脚本调用的。

我做错了什么?我在 Xcode 10.2 和 React Native 0.59.3 上。

【问题讨论】:

    标签: ios xcode react-native xcodebuild xcode10


    【解决方案1】:

    根据错误确保已安装“react-native”模块您不在项目根路径上。所以删除派生数据并打开终端并设置项目路径

    cd ../projectpath_foldername
    

    运行命令

    npm start
    

    之后

    react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
    

    现在运行

    react-native run-ios
    

    一旦构建并运行,打开 xcode 并存档您的应用程序。

    【讨论】:

    • 实际上我是从 React Native 项目根路径运行代码,但我会尝试您建议的其他部分并更新您。
    • 试过了。一切都建立在同一点之前。再次遇到完全相同的错误。
    • 你已经运行 npm start
    • 停止了 Metro Bundler(使用 Ctrl+Z)和相当终端
    • 重新打开并运行 react-native start
    【解决方案2】:

    在调查了https://github.com/facebook/react-native/issues/22354等一些问题后,我在几个小时后发现了问题:

    我的项目路径中有一个空格。我已将我的项目移至没有空间的路径,并且它开始完美存档。显然,这确实是 React Native 的一个错误。

    【讨论】:

      最近更新 更多