Example iOS fails to build
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
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.
- https://stackoverflow.com/a/72566345
- https://stackoverflow.com/questions/44492197/react-native-ios-build-cant-find-node
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.
Can you provide a link to the generated project?
@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
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.
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 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.
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.
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.
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 */);