【问题标题】:main.jsbundle does not exist. this must be a bug with + echo 'react nativemain.jsbundle 不存在。这一定是 + echo 'react native 的错误
【发布时间】:2018-09-05 10:09:42
【问题描述】:

我尝试在 XCode9.2 上使用 Product > Archive 归档我的 react native 项目。但是 Xcode 产生了这个错误:

File /Users/louis/Library/Developer/Xcode/DerivedData/Scavenger-evyvzocndqoghkclcbwewolywniz/Build/Products/Release-iphoneos/Scavenger.app/main.jsbundle does not exist. This must be a bug with


My Environment:
  OS: macOS Sierra 10.12.6
  Node: 9.3.0
  npm: 5.5.1
  Watchman: 4.7.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: ^16.0.0 => 16.2.0
  react-native: ^0.50.3 => 0.50.4

我也尝试在终端上运行
react-native bundle --entry-file='index.ios.js' --bundle-output='./ios/Scavenger/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'但最终出现错误正在加载依赖关系图... JSON 输入意外结束

XCode 错误。

【问题讨论】:

  • 除了添加截图之外,可能最好在问题中发布相关的错误消息内容
  • "build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'" 而不是这个命令我把 node --max_old_space_size=4096 ./node_modules/react-native bundle --entry-file='index.js' --bundle-output='./ios/ main.jsbundle' --dev=false --platform='ios' 因为堆内存错误但我无法找到 main.jsbundle 的位置。有什么帮助吗?
  • 查看这个视频为我解决了这个问题youtube.com/…

标签: xcode react-native


【解决方案1】:

在 AppDelegate.m 中注释此行

 jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 

使用这一行:-

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 

然后运行这个来制作 jsbundle:-

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

在 xcode 中执行此命令后运行。 希望它会捆绑并且之后没有这样的错误...... 谢谢

【讨论】:

  • 您好,感谢您的回答。但我确实更改了 AppDelegate.m 的部分,并在终端上给了我错误 "Unexpected end of JSON input"。知道为什么我会收到 JSON 错误吗?
  • 请检查您调用 api 的 ypur json 数据并检查导入 ....有时它也会给出拼写错误...所以检查导入中的任何拼写并正确获取..跨度>
  • 我收到此错误:扫描文件夹中的符号链接 /Users/(UserName)/(AppName)-IPA/trunk/node_modules (18ms) 扫描文件夹中的符号链接 /Users/(UserName)/( AppName)-IPA/trunk/node_modules (28ms) 加载依赖图,完成。警告:转换缓存已重置。无效的资产解析
  • 确保在进行此更改后继续构建之前删除 ~/Library/Developer/Xcode 中的派生数据。它对我有用,谢谢。
【解决方案2】:

我重写 shell 脚本后问题解决了。 项目 > 构建阶段 > 捆绑 React Native 代码和图像。脚本中有空格字符。

【讨论】:

  • 你能解释一下吗,我不明白。你做了什么?
  • 我看不出这有什么关系。请详细说明。
  • 我删除了脚本末尾的空白字符,它成功了
【解决方案3】:

当您的项目中没有离线捆绑文件时会发生这种情况,我遇到了同样的问题,这对我有用。

我已经在我的 package.json 文件的 scripts 部分下添加了下面的行,所以我不必在每次想要生成离线包时都输入它。

"build:ios": "react-native bundle --entry-file='index.ios.js' --bundle-output='./ios/YourAppName/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'"

然后在您的应用程序项目文件夹中运行此命令:

npm run build:ios

运行上述命令后,会在你的ios/YourAppName目录下生成新的main.jsbundle

接下来,使用 XCode 打开您的项目,右键单击您的项目名称,然后单击 Add Files to "YourProjectName",选择生成的 main.jsbundle 文件,然后再次构建。

现在它可能运行良好。

我正在使用:

 "react": "16.0.0-alpha.12",
 "react-native": "^0.48.3",

【讨论】:

  • 谢谢!为我工作。
  • 对我来说,我需要将index.ios.js 更改为index.js
  • 这应该被标记为答案!
【解决方案4】:

就我而言,从 RN 0.53.3 更新到 0.55.4 后,我在存档时收到此错误

/Users/<myuser>/Desktop/projects/<myProjectName>mobileapp/index.ios.js: Plugin 0 specified in "/Users/<myUserName>/Desktop/projects/<myProjectName>mobileapp/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "/Users/<myUserName>/Desktop/projects/<myProjectName>mobileapp/node_modules/babel-preset-react-native/index.js")

+ [[ false != true ]]
+ [[ ! -f /Users/<myUserName>/Library/Developer/Xcode/DerivedData/<myProjectName>Mobile-ghzbbftkebcwlvayfocqahvzifbe/Build/Intermediates.noindex/ArchiveIntermediates/<myProjectName>Mobile/BuildProductsPath/Release-iphoneos/<myProjectName>Mobile.app/main.jsbundle ]]
+ echo 'error: File /Users/<myUserName>/Library/Developer/Xcode/DerivedData/<myProjectName>Mobile-ghzbbftkebcwlvayfocqahvzifbe/Build/Intermediates.noindex/ArchiveIntermediates/<myProjectName>Mobile/BuildProductsPath/Release-iphoneos/<myProjectName>Mobile.app/main.jsbundle does not exist. This must be a bug with'
error: File /Users/<myUserName>/Library/Developer/Xcode/DerivedData/<myProjectName>Mobile-ghzbbftkebcwlvayfocqahvzifbe/Build/Intermediates.noindex/ArchiveIntermediates/<myProjectName>Mobile/BuildProductsPath/Release-iphoneos/<myProjectName>Mobile.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'
React Native, please report it here: https://github.com/facebook/react-native/issues
+ exit 2

解决此问题的一个重要问题是与 babel-preset-react-native

相关的错误上方的行

经过数小时尝试多种解决方法后,我找到了一个解决方案,将 babel-preset-react-native^5.0.2 降级到 ^4.0.0 以使存档过程正常工作。

【讨论】:

    【解决方案5】:

    这个问题需要我几天时间才能解决。在 travis-ci 上运行构建时遇到了这个问题。 这是我的解决方法:

    将此行添加到您的 package.json 文件中的 scripts

    "build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'"
    

    现在您可以运行命令生成main.jsbundleyarn build:iosnpm run build:ios

    打开 Xcode > 选择项目目标 > 在 Build Phases 中将 main.jsbundle 添加到 Copy Bundle Resource。 (下图)。

    【讨论】:

    • 我收到此错误:扫描文件夹中的符号链接 /Users/(UserName)/(AppName)-IPA/trunk/node_modules (18ms) 扫描文件夹中的符号链接 /Users/(UserName)/( AppName)-IPA/trunk/node_modules (28ms) 加载依赖图,完成。警告:转换缓存已重置。无效的资产解析
    • "build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'" 而不是这个命令我把 node --max_old_space_size=4096 ./node_modules/react-native bundle --entry-file='index.js' --bundle-output='./ios/ main.jsbundle' --dev=false --platform='ios' 因为堆内存错误但我无法找到 main.jsbundle 的位置。有什么帮助吗?
    • 复制捆绑资源步骤对我来说是关键!非常感谢
    • 完美运行!谢谢。
    • 感谢您的解决方案。出于某种原因安装“react-native-purchases”后我遇到了这个问题(这个库只适用于 rn 版本 0.64+,所以可能与此有关..)我的问题是..我应该每次运行 'yarn build:ios'在我存档以部署我的应用程序的新版本之前?我很困惑为什么它在我安装“react-native-purchases”之前运行良好,而这个问题在安装它之后发生..所以在我的部署过程中添加这个额外的步骤..任何信息都会非常感激!
    【解决方案6】:

    在 Xcode 中清理项目对我有帮助

    【讨论】:

    • 根本没有帮助。
    • 在 Xcode 10 中清理构建文件夹和构建,也为我解决了问题
    【解决方案7】:

    推荐使用最新的 Xcode 和 React Native 版本。 我的 React Native 版本:0.56 和 Xcode 10

    第 1 步: 更改 AppDelegate.m 文件

        //  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    #ifdef DEBUG
      jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    #else
      jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
    #endif
    

    第 2 步: 将 Xcode 构建配置更改为“发布”

    转到产品>方案>编辑方案>将调试更改为发布

    如果您使用的是 Xcode 10+,请在 File> ProjectWorkSpace Settings> Build System 下将 Build system 更改为 Legacy Build System

    第 3 步: 将您的“babel-preset-react-native”升级到 5.0.1,如果您的 package.json 文件中不存在,请添加它.

    删除 NodeModules 和 package.lock 文件并添加它(npm install 或 yarn install)。

    第 4 步: 更改“.babelrc.js”文件

    添加“presets: ["module:metro-react-native-babel-preset"]

    第 5 步: 打开终端

    打开终端并导航到您的项目目录运行此命令

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

    这将在 iOS 文件夹中生成一个“main.jsbundle”文件

    第 6 步: 将“main.jsbundle”文件添加到 Xcode 中。

    打开 Xcode 并导航到“复制捆绑资源”下的“构建阶段”添加“main.jsbundle”文件。

    清理您的项目也清除您在 Xcode 中的派生数据。 这将以发布模式构建您的项目。

    对于“存档”错误

    将此依赖项添加到您的“pod 文件”中

    pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'CxxBridge'
      ]
    pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
    pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
    pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
    pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
    

    删除 pod 和 pod.lock 并再次添加。 (吊舱安装)

    快乐编码 :)

    【讨论】:

    • Vinod,这几乎对我有用,然后我收到 react-native-input-scroll-view 的语法错误
    • 这可能是因为您的 UI 代码。请评论并尝试。
    • Vinod,我删除了react-native-input-scroll-view 并且main.jsbundle 已成功创建,但是您如何清除Xcode 中的派生数据,因为即使使用main.jsbundle,我的应用程序仍在静默崩溃。跨度>
    • @Daniel 你有什么解决方案可以解决为什么它在这里崩溃
    • @sejn,抱歉,我不记得这是如何解决的。
    【解决方案8】:

    在我的情况下,它是由 javascript 代码引起的。 Metro Bundler(命令行)中显示的错误。检查 Metro Bundler,是否有错误。

    【讨论】:

      【解决方案9】:

      这个命令对我有用。

      react-native bundle --entry-file ./index.ios.js --platform ios --bundle-output ios/main.jsbundle
      

      【讨论】:

      • 这不是解决方案。
      【解决方案10】:

      在我的情况下,这是由我的项目路径中的空格字符引起的:/users/USER/Projects/Project HousePlants/

      捆绑包中Project Houseplants 中的空间无法处理,因此无法找到您的main.jsbundle

      确保路径中没有空白字符,然后重试。

      See this answer

      【讨论】:

        【解决方案11】:

        您需要运行以下命令:

        react-native bundle --entry-file ./index.js --platform ios --bundle-output ios/main.jsbundle
        

        之后,带有静态包的应用程序将安装在真实设备上。但是由于静态文件的性质,每当我修改源代码时,我都需要再次运行该命令以反映更改。 (您可以在命令中看到下一个错误)

        【讨论】:

          【解决方案12】:

          对于像我这样的人来说,这只是 JavaScript 代码中的错误指示。我在输入以下命令后发现是这种情况:npx react-native bundle --entry-file index.js --bundle-output "bundle.bundle"。 Android 用户需要像这样指定平台:npx react-native bundle --entry-file --platform "ios" index.js --bundle-output "bundle.bundle"

          捆绑失败并显示语法错误。任何在模拟器中打开违规代码的尝试也会显示错误。

          【讨论】:

            【解决方案13】:

            如果您更新 xcode 并收到此错误,则解决方案是

            在你的根项目的终端触发以下命令

             1. sudo xcode-select --reset
            
             2. npx react-native bundle --entry-file ./index.js --platform ios --bundle-output ios/main.jsbundle
            

            在第二个命令中,如果您发现任何与 JS 相关的错误,请修复它 成功运行第二个命令后,此错误将消失

            【讨论】:

            • 该命令正在创建一个以前不存在的资产文件夹,我的应用程序的许多图像也消失了
            【解决方案14】:

            在我退出展会以添加应用内购买后,我遇到了这个问题。 我做了以下工作来让它工作

            cd <your repo>
            npx react-native bundle --entry-file ./index.js --dev false --reset-cache --platform ios --bundle-output ios/main.jsbundle --assets-dest ./ios
            

            运行上述命令后,您必须将 main.jsbundle 和资产拖放到您的 Xcode 中,并通过引用而不是分组来链接它

            【讨论】:

              【解决方案15】:

              如果配置文件的属性在运行时发生变化,请确保其中没有错误,如果属性设置不正确,则不会生成 main.bundlejs。

              例如:

              isSent:false, 
              isShow:false
              

              这两个属性是在运行时设置的,发现对于特定记录,isSent 和 isShow 没有设置

              isSent:,
              isShow:
              

              在运行时并导致错误。

              【讨论】:

                【解决方案16】:

                你可以运行:

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

                【讨论】:

                  【解决方案17】:

                  PFB 我运行的命令,解决了问题。

                  1. npm 我
                  2. cd ios
                  3. pod 安装

                  【讨论】:

                    猜你喜欢
                    • 2020-10-29
                    • 1970-01-01
                    • 2022-11-02
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-01-16
                    • 1970-01-01
                    • 2018-09-09
                    • 2020-07-13
                    相关资源
                    最近更新 更多