Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode scripts should not use node from path #3472

Closed
6 of 11 tasks
jahead opened this issue Dec 14, 2023 · 4 comments · Fixed by #3493
Closed
6 of 11 tasks

Xcode scripts should not use node from path #3472

jahead opened this issue Dec 14, 2023 · 4 comments · Fixed by #3493

Comments

@jahead
Copy link

jahead commented Dec 14, 2023

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @sentry/react-native (>= 1.0.0)
  • react-native-sentry (<= 0.43.2)

SDK version: 5.15.1

react-native version: 0.73.0
xcode version: 15

Are you using Expo?

  • Yes
  • No

Are you using sentry.io or on-premise?

  • sentry.io (SaaS)
  • on-premise

Configuration:

(@sentry/react-native)

    Sentry.init({
      dsn: 'https://<>.ingest.sentry.io/<>',

      integrations: [
        new Sentry.ReactNativeTracing({
          // Pass instrumentation to be used as `routingInstrumentation`
          routingInstrumentation,
        }),

I have the following issue:

Steps to reproduce:

  • initialise new 0.73.0 app
  • npx @sentry/wizard@latest -s -i reactNative
  • follow prompts

Actual result:

Node found at: /Users/jahead/.nvm/versions/node/v18.16.1/bin/node
+ '[' -z '' ']'
+ export SENTRY_PROPERTIES=sentry.properties
+ SENTRY_PROPERTIES=sentry.properties
+ '[' -z '' ']'
+ export SOURCEMAP_FILE=/Users/jahead/Library/Developer/Xcode/DerivedData/BcsInspectionsMobileApp-hacdehfiinxqoeejynnmlpgagqow/Build/Intermediates.noindex/BcsInspectionsMobileApp.build/Debug-iphoneos/BcsInspectionsMobileApp.build/DerivedSources/main.jsbundle.map
+ SOURCEMAP_FILE=/Users/jahead/Library/Developer/Xcode/DerivedData/BcsInspectionsMobileApp-hacdehfiinxqoeejynnmlpgagqow/Build/Intermediates.noindex/BcsInspectionsMobileApp.build/Debug-iphoneos/BcsInspectionsMobileApp.build/DerivedSources/main.jsbundle.map
+ '[' -z '' ']'
+ SENTRY_CLI_EXECUTABLE=../node_modules/@sentry/cli/bin/sentry-cli
+ REACT_NATIVE_XCODE=../node_modules/react-native/scripts/react-native-xcode.sh
+ [[ '' != true ]]
+ [[ -z '' ]]
+ NO_AUTO_RELEASE=--no-auto-release
+ ARGS='--no-auto-release  '
+ REACT_NATIVE_XCODE_WITH_SENTRY='"../node_modules/@sentry/cli/bin/sentry-cli" react-native xcode --no-auto-release   "../node_modules/react-native/scripts/react-native-xcode.sh"'
+ '[' '' '!=' true ']'
+ /bin/sh -c '"../node_modules/@sentry/cli/bin/sentry-cli" react-native xcode --no-auto-release   "../node_modules/react-native/scripts/react-native-xcode.sh"'
env: node: No such file or directory

Expected result:
For automatic scripts to work.


What I think is happening here is that sentry is making some incorrect assumptions to how WITH_ENVIRONMENT works.
And environments that do not have a default node installation breaks sentry's automatic scripts.
As environments that are managed by node version managers, i.e. nvm may not have a node in the path

For context xcode.env.local

export NODE_BINARY=/Users/jahead/.nvm/versions/node/v18.16.1/bin/node

While with-environment.sh does expose NODE_BINARY it does not put node on the path, and if node is not on the path when xcode runs the phase because we are using a node manager the sentry scripts will crash
You can actually fix the issue with sentry-xcode.sh with

diff --git a/node_modules/@sentry/react-native/scripts/sentry-xcode.sh b/node_modules/@sentry/react-native/scripts/sentry-xcode.sh
index bf024ea..ddca86e 100755
--- a/node_modules/@sentry/react-native/scripts/sentry-xcode.sh
+++ b/node_modules/@sentry/react-native/scripts/sentry-xcode.sh
@@ -19,7 +19,7 @@ ARGS="$NO_AUTO_RELEASE $SENTRY_CLI_EXTRA_ARGS $SENTRY_CLI_RN_XCODE_EXTRA_ARGS"
 REACT_NATIVE_XCODE_WITH_SENTRY="\"$SENTRY_CLI_EXECUTABLE\" react-native xcode $ARGS \"$REACT_NATIVE_XCODE\""
 
 if [ "$SENTRY_DISABLE_AUTO_UPLOAD" != true ]; then
-  /bin/sh -c "$REACT_NATIVE_XCODE_WITH_SENTRY"
+  /bin/sh -c "$NODE_BINARY $REACT_NATIVE_XCODE_WITH_SENTRY"
 else
   echo "SENTRY_DISABLE_AUTO_UPLOAD=true, skipping sourcemaps upload"
   /bin/sh -c "$REACT_NATIVE_XCODE"

By adding in the $NODE_BINARY in the script call.
For sentry-xcode-debug-files.sh is a bit more tricky, while I'm not 100% on the cause but from reading the script the issue is the that when using the WITH_ENV script inside the sentry-xcode-debug-files.sh it is isn't able to read the xcode.env which defaults to NODE_BINARY=$(command -v node) which would require the system to have a default node.

I got this working by, running the WITH_ENV script in the phase like so

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

/bin/sh -c "$WITH_ENVIRONMENT ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh"
diff --git a/node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh b/node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh
index 73ab003..5203fc5 100755
--- a/node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh
+++ b/node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh
@@ -5,12 +5,6 @@
 # print commands before executing them and stop on first error
 set -x -e
 
-# load envs if loader file exists (since rn 0.68)
-WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
-if [ -f "$WITH_ENVIRONMENT" ]; then
-    . "$WITH_ENVIRONMENT"
-fi
-
 [ -z "$SENTRY_PROPERTIES" ] && export SENTRY_PROPERTIES=sentry.properties
 [ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_EXECUTABLE="../node_modules/@sentry/cli/bin/sentry-cli"
 
@@ -21,7 +15,7 @@ EXTRA_ARGS="$SENTRY_CLI_EXTRA_ARGS $SENTRY_CLI_DEBUG_FILES_UPLOAD_EXTRA_ARGS $IN
 UPLOAD_DEBUG_FILES="\"$SENTRY_CLI_EXECUTABLE\" debug-files upload $EXTRA_ARGS \"$DWARF_DSYM_FOLDER_PATH\""
 
 if [ "$SENTRY_DISABLE_AUTO_UPLOAD" != true ]; then
-  /bin/sh -c "$UPLOAD_DEBUG_FILES"
+  /bin/sh -c "$NODE_BINARY $UPLOAD_DEBUG_FILES"
 else
   echo "SENTRY_DISABLE_AUTO_UPLOAD=true, skipping debug files upload"
 fi

Lastly, you are missing setting up the input files on Upload Debug Symbols to Sentry on the automatic installation

			inputPaths = (
				"$(SRCROOT)/.xcode.env.local",
				"$(SRCROOT)/.xcode.env",
			);

This will allow sentry to follow the same behavior that react native is following.


So TLDR:

  • sentry isn't able to find node for systems that are using a node version manager
  • sentry currently can be using a different node version then what is set in the xcode.env
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Dec 14, 2023
@jahead jahead changed the title node: No such file or directory node: No such file or directory with automatic scripts Dec 14, 2023
@krystofwoldrich
Copy link
Member

krystofwoldrich commented Dec 15, 2023

Hi,
thank you for the very detailed description.

We agree the $NODE_BINARY should be used exclusively and there should be no references to a node from $PATH.

The core of the issue comes from a misunderstanding ../node_modules/@sentry/cli/bin/sentry-cli is not an executable binary, but a JS file referencing the node from the environment.

I have tested the following code and loading the envs from .xcode.env and .xcode.env.local works as expected in sentry-xcode-debug-files.sh.

# load envs if loader file exists (since rn 0.68)
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
if [ -f "$WITH_ENVIRONMENT" ]; then
    . "$WITH_ENVIRONMENT"
fi
+ WITH_ENVIRONMENT=../node_modules/react-native/scripts/xcode/with-environment.sh
+ '[' -f ../node_modules/react-native/scripts/xcode/with-environment.sh ']'
+ . ../node_modules/react-native/scripts/xcode/with-environment.sh
+++ command -v node
++ NODE_BINARY=/usr/local/bin/node
++ export NODE_BINARY
++ ENV_PATH=/Users/krystofwoldrich/random/reproducer-sentry/ios/Pods/../.xcode.env
++ '[' -f /Users/krystofwoldrich/random/reproducer-sentry/ios/Pods/../.xcode.env ']'
++ source /Users/krystofwoldrich/random/reproducer-sentry/ios/Pods/../.xcode.env
++++ command -v node
+++ export NODE_BINARY=/usr/local/bin/node
+++ NODE_BINARY=/usr/local/bin/node
++ LOCAL_ENV_PATH=/Users/krystofwoldrich/random/reproducer-sentry/ios/Pods/../.xcode.env.local
++ '[' -f /Users/krystofwoldrich/random/reproducer-sentry/ios/Pods/../.xcode.env.local ']'
++ source /Users/krystofwoldrich/random/reproducer-sentry/ios/Pods/../.xcode.env.local
+++ export NODE_BINARY=/Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node
+++ NODE_BINARY=/Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node
+++ export SENTRY_PROJECT=sentry-react-native
+++ SENTRY_PROJECT=sentry-react-native
+++ export SENTRY_ORG=sentry-sdks
+++ SENTRY_ORG=sentry-sdks
+++ export SENTRY_AUTH_TOKEN=-----REDACTED-----
+++ SENTRY_AUTH_TOKEN=-----REDACTED-----
+++ export SENTRY_CLI_EXTRA_ARGS=--force-foreground
+++ SENTRY_CLI_EXTRA_ARGS=--force-foreground
++ '[' -n /Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node ']'
++ echo 'Node found at: /Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node'
Node found at: /Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node
++ '[' -n '' ']'
+ '[' -z '' ']'
+ export SENTRY_PROPERTIES=sentry.properties
+ SENTRY_PROPERTIES=sentry.properties
+ '[' -z '' ']'
+ SENTRY_CLI_EXECUTABLE=../node_modules/@sentry/cli/bin/sentry-cli
+ [[ '' == \t\r\u\e ]]
+ INCLUDE_SOURCES_FLAG=
+ EXTRA_ARGS='--force-foreground  '
+ UPLOAD_DEBUG_FILES='"/Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node" "../node_modules/@sentry/cli/bin/sentry-cli" debug-files upload --force-foreground   "/Users/krystofwoldrich/Library/Developer/Xcode/DerivedData/MyApp-gggmlzayhrnytdaotrsrtridrzmz/Build/Products/Release-iphonesimulator"'
+ '[' '' '!=' true ']'
+ /bin/sh -c '"/Users/krystofwoldrich/.nvm/versions/node/v20.5.1/bin/node" "../node_modules/@sentry/cli/bin/sentry-cli" debug-files upload --force-foreground   "/Users/krystofwoldrich/Library/Developer/Xcode/DerivedData/MyApp-gggmlzayhrnytdaotrsrtridrzmz/Build/Products/Release-iphonesimulator"'

Thank you for mentioning the inputPaths we will add those to the Upload Debug Symbols to Sentry.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 Dec 15, 2023
@krystofwoldrich krystofwoldrich changed the title node: No such file or directory with automatic scripts Xcode scripts should not use node from path Dec 15, 2023
@krystofwoldrich krystofwoldrich moved this from Needs Discussion to Todo in Mobile & Cross Platform SDK Dec 15, 2023
@krystofwoldrich krystofwoldrich moved this from Todo to Backlog in Mobile & Cross Platform SDK Dec 15, 2023
@krystofwoldrich krystofwoldrich moved this from Backlog to Todo in Mobile & Cross Platform SDK Dec 15, 2023
@jahead
Copy link
Author

jahead commented Dec 16, 2023

Awesome looks like it will be fixed, I wasn't sure how my English was - it was 2am in the morning ;/

Just clarifying that you saying that with-environment.sh in sentry-xcode-debug-files.sh worked as expected? If so that's interesting, maybe I was getting lost in my own debug session. I'll wait until you guys finish the patch and retest.

I will leave my patch in until this issue is resolved. Looking forward to the fix! - let me know if you need me to test anything.

Also, thanks for coming up with a better title :D

@Yuniac
Copy link

Yuniac commented Jan 10, 2024

Hi, I'm having the same issue. XCODE 15.1 and sentry/react-native 5.11.1 and I can't build using XCODE:

line 5: ../node_modules/@sentry/cli/bin/sentry-cli: No such file or directory

Will this PR fix this issue #3493? or do I need to fix it manually somehow?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Jan 10, 2024
@krystofwoldrich
Copy link
Member

@Yuniac This seems like the path ../node_modules/@sentry/cli/bin/sentry-cli doesn't exist. Usually, that is caused by sentry-cli not being installed correctly or the node_modules folder existing somewhere else in your project structure.

This was resolved in #3507 and is currently available in https://github.com/getsentry/sentry-react-native/releases/tag/5.16.0-alpha.4

You can also manually set the path to the sentry-cli by SENTRY_CLI_EXECUTABLE env.
https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#configure-automatic-source-maps-upload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants