react-native-builder-bob icon indicating copy to clipboard operation
react-native-builder-bob copied to clipboard

Example iOS fails to build

Open icc-romeu opened this issue 3 years ago β€’ 10 comments

Description

When creating a clean project, the example iOS app fails to build. It cannot find the right react native script. The Bundle React Native code and images task fails due to missing files.

This is the content

set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"

There is nothing in that path for the example folder.

If the previous project is used (that is, the ../../node_modules...) Then it fails to find react native.

Packages

  • [X] create-react-native-library
  • [ ] react-native-builder-bob

Selected options

βœ” What type of library do you want to develop? β€Ί Native module βœ” Which languages do you want to use? β€Ί Kotlin & Swift

Link to repro

No response

Environment

System: OS: macOS 14.0 CPU: (8) arm64 Apple M1 Memory: 79.41 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 16.17.1 path: ~/.nvm/versions/node/v16.17.1/bin/node Yarn: version: 1.22.19 path: ~/.yarn/bin/yarn npm: version: 8.15.0 path: ~/.nvm/versions/node/v16.17.1/bin/npm Watchman: version: 4.9.0 path: /usr/local/bin/watchman Managers: CocoaPods: version: 1.14.2 path: /Users/pablo/.rbenv/shims/pod SDKs: iOS SDK: Platforms: - DriverKit 23.0 - iOS 17.0 - macOS 14.0 - tvOS 17.0 - watchOS 10.0 Android SDK: Android NDK: 21.0.6113669 IDEs: Android Studio: Not Found Xcode: version: 15.0.1/15A507 path: /usr/bin/xcodebuild Languages: Java: version: 11.0.16.1 path: /Users/pablo/.jenv/shims/javac Ruby: version: 3.2.2 path: /Users/pablo/.rbenv/shims/ruby npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.6 wanted: 0.72.6 react-native-macos: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: false newArchEnabled: false iOS: hermesEnabled: Not found newArchEnabled: Not found

icc-romeu avatar Nov 02 '23 08:11 icc-romeu

Hey, I just want to make sure that this is an issue with the crnl itself. Could you check the following Stack Overflow issues and try to see if they fix the issue for you? I'm asking because there is a common problem with nvm and Xcode builds of React Native.

  1. https://stackoverflow.com/a/72566345
  2. https://stackoverflow.com/questions/44492197/react-native-ios-build-cant-find-node

atlj avatar Nov 02 '23 13:11 atlj

He @atlj thanks for your fast response.

Indeed I did run nvm install before starting the whole project and I got node 18 installed for the folder. And no, it is not a node issue. Node works properly. The issue is with Xcode building the example app. It does not find react native where it should be.

As I am creating a library with the yarn workspaces in place, react-native is not inside node-modules but in the root folder:

AwesomeLibrary\
    node_modules\
        react-native <--  This is the actual react native
    example\
        node-modules <--- This node_modules is empty.
        ios

So the folder that Bundle React Native code and images is looking for is not there. Obviously if I change the folder then it works. It starts the app but then Metro complains about react native when the app is started.

Maybe this has to do with macOS 14 Sonoma or Xcode 15.

icc-romeu avatar Nov 02 '23 14:11 icc-romeu

Can you provide a link to the generated project?

satya164 avatar Nov 24 '23 12:11 satya164

@icc-romeu @satya164 i was have same issue, this problem occurs when you use npm instead of yarn, using yarn causes correct installation of node_modules in both folders

rastuch avatar Dec 06 '23 11:12 rastuch

The same here, it is caused by the presence of

  "workspaces": [
    "example"
  ],

in the generated project root's package.json β€” if you remove it from there, then node_modules is independently created both in the root, and in the example folders, when running npm install in them. This is the first time I've learned about this features (NPM Workspaces), at glance it seems that this behavior is consistent with documentation of that feature, but I am not sure how Gradle Plugin (I came across the issue when upgrading an Android version of my lib) & RN setup is supposed to play along with it.

birdofpreyru avatar Dec 08 '23 02:12 birdofpreyru

As mentioned in the generated CONTRIBUTING.md, the generated project requires Yarn. If you want to use npm then you'll need to adjust the generated project accordingly.

satya164 avatar Dec 08 '23 02:12 satya164

@satya164 To me the documentation at https://callstack.github.io/react-native-builder-bob/create and https://callstack.github.io/react-native-builder-bob/build does not suggest that scaffolded library projects do not support NPM, on contrary, NPM is mentioned in a few places there as a legit alternative to use; and generated projects worked fine with NPM out of the box as recent as this summer at least. I don't see a mention that you broke NPM support at https://github.com/callstack/react-native-builder-bob/releases, and CONTRIBUTING.md in the generated library code is probably the last place I'd look into for such details.

birdofpreyru avatar Dec 08 '23 03:12 birdofpreyru

and CONTRIBUTING.md in the generated library code is probably the last place I'd look into for such details

You're told to check it after generating the project, it is mentioned in the README of your project for development workflow, and it's also mentioned on the page that you linked to.

All of the development workflow is documented in CONTRIBUTING.md and not on our website - it makes more sense to have it there as contributors will check in your repo, not our website, and the workflow may change. I think it's quite fair to expect that you'll at least go through the README of your own project even if you missed the message telling you to check CONTRIBUTING.md.

on contrary, NPM is mentioned in a few places there as a legit alternative to use

It's nowhere mentioned that npm can be used as an alternative in the generated project. The only place it's mentioned in is for local library which is a different use case.

I don't see a mention that you broke NPM support

The development workflow has always mentioned Yarn and npm was never supported or tested with the generated project.

satya164 avatar Dec 08 '23 03:12 satya164

I’ll just say, given I’m not the first nor the only one to bump into it, although it seems so obvious and logical to you, it doesn’t to some users. IMHO adding a warning on top of documentation I referred to will help to avoid unnecessary confusion of some users in future.

birdofpreyru avatar Dec 08 '23 20:12 birdofpreyru

Sorry for the long delay. The documentation expects you to use

npx create-react-native-library@latest react-native-library-test

This usually uses npmnot yarn. you have to add --use-yarn to force yarn to be used.

Nevertheless I could no reproduce the error. As now the builder fails for me -both with npm and yarn- on creation:

pablo@Pablos-MacBook-Air test-library % npx create-react-native-library@latest react-native-library-test 
βœ” What is the name of the npm package? … react-native-library-test
βœ” What is the description for the package? … a
βœ” What is the name of package author? … Pablo Romeu
βœ” What is the email address for the package author? … [email protected]

βœ” What is the URL for the package author? … https://github.com/icc-romeu
βœ” What is the URL for the repository? … https://github.com/icc-romeu/react-native-library-test
βœ” What type of library do you want to develop? β€Ί Native module
βœ” Which languages do you want to use? β€Ί Kotlin & Swift
β § Generating example app

ENOENT: no such file or directory, open '/Users/pablo/Downloads/test-library/react-native-library-test/example/package.json'
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);

icc-romeu avatar Jan 09 '24 07:01 icc-romeu