cli: [monorepo] bundling doesn't work (workaround available)

To kick off: I also posted clone of this issue in rn repo https://github.com/facebook/react-native/issues/26259

Although I’m almost sure that it is related to cli somehow due to errors that get output. My instinct is either something changed to platform flag where ios value is invalid or due to usage of multiple cli paths while archiving. Full details below. If this does sound like a cli issue, I’ll close one in rn, if not will do vice versa.

React Native version:

System:
    OS: macOS 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 362.14 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.0 - /usr/local/opt/node@10/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/opt/node@10/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild

Steps To Reproduce

  1. Choose Generic iOS Device as your build target
  2. Clean build folder
  3. Archive (Should archive build without issues, but fails)

Error

Towards the end of the build following error pops up, tried cleaning derived data and caches, but this happens consistently:

TL;DR I think actionable bits are error Invalid platform "ios" selected. and main.jsbundle does not exist.

Also looks like cli commands are ran from different directories, both of these are present in the output: /node_modules/react-native/cli.js and /node_modules/@react-native-community/cli

I’ve started getting this error when I upgraded from 0.59 to 0.61rc. What confuses me is that my normal “DEBUG” builds are working fine.


Showing All Errors Only
:-1: + BUNDLE_FILE=/Users/ilja/Library/Developer/Xcode/DerivedData/myTestApp-fluhnhqokfrubpemalkqqwtmqwql/Build/Intermediates.noindex/ArchiveIntermediates/myTestAppDevelopment/BuildProductsPath/Release-iphoneos/myTestAppDevelopment.app/main.jsbundle

:-1: + node /Users/ilja/Documents/GitHub/myTestApp/node_modules/react-native/cli.js bundle --entry-file packages/myTestApp-app/index.js --platform ios --dev false --reset-cache --bundle-output /Users/ilja/Library/Developer/Xcode/DerivedData/myTestApp-fluhnhqokfrubpemalkqqwtmqwql/Build/Intermediates.noindex/ArchiveIntermediates/myTestAppDevelopment/BuildProductsPath/Release-iphoneos/myTestAppDevelopment.app/main.jsbundle --assets-dest /Users/ilja/Library/Developer/Xcode/DerivedData/myTestApp-fluhnhqokfrubpemalkqqwtmqwql/Build/Intermediates.noindex/ArchiveIntermediates/myTestAppDevelopment/BuildProductsPath/Release-iphoneos/myTestAppDevelopment.app

:-1: error Invalid platform "ios" selected.

:-1: info Available platforms are: "native". If you are trying to bundle for an out-of-tree platform, it may not be installed.

:-1: error Bundling failed. Run CLI with --verbose flag for more details.

:-1: Error: Bundling failed

:-1:     at buildBundle (/Users/ilja/Documents/GitHub/myTestApp/node_modules/@react-native-community/cli/build/commands/bundle/buildBundle.js:80:11)

:-1:     at async Command.handleAction (/Users/ilja/Documents/GitHub/myTestApp/node_modules/@react-native-community/cli/build/cliEntry.js:160:7)

:-1: + [[ false != true ]]

:-1: + [[ ! -f /Users/ilja/Library/Developer/Xcode/DerivedData/myTestApp-fluhnhqokfrubpemalkqqwtmqwql/Build/Intermediates.noindex/ArchiveIntermediates/myTestAppDevelopment/BuildProductsPath/Release-iphoneos/myTestAppDevelopment.app/main.jsbundle ]]

:-1: + echo 'error: File /Users/ilja/Library/Developer/Xcode/DerivedData/myTestApp-fluhnhqokfrubpemalkqqwtmqwql/Build/Intermediates.noindex/ArchiveIntermediates/myTestAppDevelopment/BuildProductsPath/Release-iphoneos/myTestAppDevelopment.app/main.jsbundle does not exist. This must be a bug with'

:-1: File /Users/ilja/Library/Developer/Xcode/DerivedData/myTestApp-fluhnhqokfrubpemalkqqwtmqwql/Build/Intermediates.noindex/ArchiveIntermediates/myTestAppDevelopment/BuildProductsPath/Release-iphoneos/myTestAppDevelopment.app/main.jsbundle does not exist. This must be a bug with

:-1: + echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'

:-1: React Native, please report it here: https://github.com/facebook/react-native/issues

:-1: + exit 2


About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 34 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Looks like we can safely revert this commit https://github.com/facebook/react-native/commit/9ccde378b6e6379df61f9d968be6346ca6be7ead and things will work automatically without any PROJECT_ROOT.

For now, the correct way of configuring is to set:

export NODE_BINARY=node
export PROJECT_ROOT=$PWD/..
../../../node_modules/react-native/scripts/react-native-xcode.sh

in a monorepo.

Please do not use the other workaround provided. It’s wrong.

Adjust the package.json in the root directory of your project where you run yarn react-native ... from, to look like this:

"dependencies": {
+  "react-native": "*",
   "other-package": "1.2.3"

I’ve had to add export PROJECT_ROOT=“$PROJECT_DIR/…” inside the xcode step

If you’re using previous workaround, please check how to migrate onto the standard and approved solution in this PR: https://github.com/brunolemos/react-native-web-monorepo/pull/52

Had the same issue on android, fixed by changing the cliPath:

project.ext.react = [
    entryFile: "packages/mobile/index.js",
    enableHermes: false,  // clean and rebuild if changing
    root: "../../../../",
    cliPath: "./cli.js" <--- add this
]

and create a cli.js in the root folder of the mono repo:

process.chdir('./packages/mobile')

var cli = require('@react-native-community/cli')
cli.run()

I never had the chance to check ios.

@brunolemos move react-native to root package.json, it has to be there in order for cli to apply ios and android as platforms here https://github.com/react-native-community/cli/blob/708211a6451ee6ac1d3575016a045b30982b3ad0/packages/cli/src/tools/loadMetroConfig.js#L38

I’ve been told better monorepo support is coming soon.

I misread your note. I thought you had this under “devDependencies”

I have

"dependencies": {
 "react-native": "0.60.5",
   "other-package": "1.2.3"

And i’m still getting the main.jsbundle does not exist. any other considerations you have or anything I should try that you can think of?

@devagul93 it’s because of how CLI looks for deps to look for (takes those from package.json and from react-native.config.js). We want to come up with a more ergonomic solution.

Alright, I’ll keep digging into my issue, will report here if I find anything interesting. Thank you for your time guys, this seems like something specific to my project.

You’re in a monorepo, that’s very important information. If you run your RN app from root of the project, you’ll currently need to add react-native to your root package.json dependencies. We’re working on better monorepo integration, but not there yet.