react-native-community / upgrade-support

A central community-backed place to request and give help when upgrading your app.
MIT License
261 stars 2 forks source link

upgrading from 0.67.1 to 0.70.2 .xcode.env command not found, Could not find node #214

Closed dannyhw closed 2 years ago

dannyhw commented 2 years ago

Environment

System:
    OS: macOS 12.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 931.36 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /var/folders/33/zfyclp250fx6crnyplm4kc8h0000gn/T/yarn--1664973970735-0.33662965696645863/node
    Yarn: 1.23.0-20211220.1904 - /var/folders/33/zfyclp250fx6crnyplm4kc8h0000gn/T/yarn--1664973970735-0.33662965696645863/yarn
    npm: 8.19.2 - /usr/local/opt/asdf/installs/nodejs/16.13.1/.npm/bin/npm
    Watchman: 2022.02.14.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8193401
    Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.14.1 - /usr/local/opt/asdf//shims/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^18.2.0 => 18.2.0 
    react-native: 0.70.2 => 0.70.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Things I’ve done to figure out my issue

The method I used to upgrade was: I regenerated the project using the typescript template and then copied over the files and updated the paths to node_modules to match the mono-repo structure.

I built the project in xcode to investigate the cause of the issue and I found that the issue is .xcode.env: command not found

Initially it seemed like the file was named incorrectly (_xcode.env) but even after changing it to .xcode.env it still isn't found.

The project doesn't have any native code other than pods included from some community packages.

Upgrading version

0.70.2

Description

When I run the project for android I have no issues, however when I build IOS I get error code 65 and when digging into the logs I find the following

.xcode.env: command not found

My project is in a mono-repo and the path to with-environment.sh works fine, however it seems like ENV_PATH="$PODS_ROOT/../.xcode.env" does not match with the path to the env file in my project.

/Users/danny/workspace/storybook/react-native/examples/native/ios/Pods/../../../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 35: .xcode.env: command not found
/Users/danny/workspace/storybook/react-native/examples/native/ios/Pods/../../../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 35: node: command not found
[Warning] You need to configure your node path in the  environment.  You can set it up quickly by running:  echo 'export NODE_BINARY=' > .xcode.env  in the ios folder. This is needed by React Native to work correctly.  We fallback to the DEPRECATED behavior of finding . This will be REMOVED in a future version.  You can read more about this here: https://reactnative.dev/docs/environment-setup#optional-configuring-your-environment
/Users/danny/workspace/storybook/react-native/examples/native/ios/Pods/../../../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh: line 41: /Users/danny/workspace/storybook/react-native/examples/native/ios/Pods/../../node_modules/react-native/scripts/find-node-for-xcode.sh: No such file or directory
[Error] Could not find node. It looks like that the .xcode.env or .xcode.env.local 

EDIT

seems like it does find .xcode.env but the command fails, if I put a static path to node in there then it gives me another error

../node_modules/react-native/scripts/xcode/with-environment.sh: No such file or directory

Still not sure why this is happening but this path does seem wrong since my node modules are at ../../../

Reproducible demo

The PR with the changes can be found here, https://github.com/storybookjs/react-native/pull/381

running the example project works as follows

yarn
yarn bootstrap --core
cd examples/native
cd ios
pod install
cd ..
yarn start
yarn ios

I will try to provide a more bare bones reproduction, however it takes some time to setup a monorepo so I'll provide it here when it's ready. Hopefully the above PR can help clarify in the meantime.

dannyhw commented 2 years ago

Turns out I needed to update a path in project.pbxproj

This is where I updated the script path

shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../../../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../../../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
fwielstra commented 1 year ago

Addendum: I found this issue with very similar issues, and where the fix mentioned by @dannyhw worked for me. However, this was in an NX project, where my app folder was two levels deeper than expected.

The intent in that setup is that there is a symlink from node_modules to ../../node_modules. This symlink, in the NX content, is only created when the user starts the app for the first time.

It's probably better to make sure this symlink exists than to edit the pbxproj file.

geetee24 commented 6 months ago

@dannyhw - where in the file project.pbxproj did you make your change?

What was the original line?

shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../../../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../../../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";

dannyhw commented 6 months ago

I basically just search for node_modules in the pbxproj file and replace as needed

geetee24 commented 6 months ago

my issue is here:

Users/aaaaaa/Library/Developer/Xcode/DerivedData/aaaaa-hbrhrjckjsvkqxdphretyodpxreh/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/hermes-engine.build/Script-46EB2E0001D250.sh: line 2: /scripts/xcode/with-environment.sh: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code

On Sun, May 12, 2024 at 10:48 AM Daniel Williams @.***> wrote:

I basically just search for node_modules in the pbxproj file and replace as needed

— Reply to this email directly, view it on GitHub https://github.com/react-native-community/upgrade-support/issues/214#issuecomment-2106325957, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS6UT77O7ERPULNYZ7MVY3ZB6TO7AVCNFSM6AAAAAAQ5RUJCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGMZDKOJVG4 . You are receiving this because you commented.Message ID: @.***>

geetee24 commented 6 months ago

/hermes-engine.build script is failing:

!/bin/sh

    . "$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"

is failing per above listing. $REACT_NATIVE_PATH is correctly set in the xcode project's user setting. but appears that the script isnt getting it.

Neeraj-WebNeuron commented 1 month ago

my issue is here: Users/aaaaaa/Library/Developer/Xcode/DerivedData/aaaaa-hbrhrjckjsvkqxdphretyodpxreh/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/hermes-engine.build/Script-46EB2E0001D250.sh: line 2: /scripts/xcode/with-environment.sh: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code On Sun, May 12, 2024 at 10:48 AM Daniel Williams @.> wrote: I basically just search for node_modules in the pbxproj file and replace as needed — Reply to this email directly, view it on GitHub <#214 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS6UT77O7ERPULNYZ7MVY3ZB6TO7AVCNFSM6AAAAAAQ5RUJCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGMZDKOJVG4 . You are receiving this because you commented.Message ID: @.>

Having same issue after upgrading to 0.73.0 React native version