microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.46k stars 132 forks source link

react-native-macos 0.74.1 fails on fresh project #2165

Closed hsjoberg closed 1 week ago

hsjoberg commented 4 weeks ago

Environment

react-native -v: 13.6.9
npm ls react-native: 0.74.5
npm ls react-native-macos: 0.74.1
node -v: v21.6.0
npm -v: 10.2.4
yarn --version: 3.6.4
xcodebuild -version: Xcode 15.4 Build version 15F31d

Steps to reproduce the bug

I tried making a fresh project through community cli, and adding react-native-macos to it through react-native-macos-init. However, building fails with the following error:

telegram-cloud-photo-size-4-5904510091678303136-x

I tried both old and new arch.

Steps to reproduce:

You can find reproducible project here: https://github.com/hsjoberg/rnmacos74

Running through cli (npx react-native-macos run-macos --scheme rnmacos74-macOS --configuration Debug) does unfortunately not give any more useful info from what I can tell. But I uploaded full log here: https://gist.github.com/hsjoberg/0145ebdf2fa5d7ab138c928222f41b09

Expected Behavior

App should successfully build.

Actual Behavior

Getting error Codegen did not run properly in your project. Please reinstall cocoapods with `bundle exec pod install`.

Reproducible Demo

https://github.com/hsjoberg/rnmacos74

Additional context

No response

morukutsu commented 3 weeks ago

From what I have tested, when running npx react-native@latest init test_project3 --version 0.74.1, if you do not install CocoaPods when prompted here ? Do you want to install CocoaPods now? Only needed if you run your project in Xcode directly › (y/N), the build will fail with the error above. Could you try this on your end?

hsjoberg commented 3 weeks ago

Okay I think I've figured it out.

There's an erroneous script [CP-User] [RN]Check rncore that runs for the React-Fabric pod. The script tries to look for codegen files in node_modules/react-native/..., whereas codegen will create them in node_modules/react-native-macos/....

The script:

echo "Checking whether Codegen has run..."
rncorePath="$REACT_NATIVE_PATH/ReactCommon/react/renderer/components/rncore"

if [[ ! -d "$rncorePath" ]]; then
  echo 'error: Codegen did not run properly in your project. Please reinstall cocoapods with `bundle exec pod install`.'
  exit 1
fi

$REACT_NATIVE_PATH will point to react-native, not react-native-macos. This would also explain why it worked for you @morukutsu when you ran the initial pod install for iOS.

As a quick fix it's possible to just clear out the script and xcode will build the project just fine. You can find the script in Xcode, under Pods -> React Fabric and then Build Phases.

But the actual proper fix is not clear to me yet.

Saadnajmi commented 3 weeks ago

Thanks for the investigation @hsjoberg !

hsjoberg commented 1 week ago

Closing this one. Seems to not be an issue anymore in react-native-macos@0.75.2 💯