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

Build fails on Xcode. Run custom shell script 'Bundle React Native code and images' #141

Closed
khagesh opened this issue Jul 7, 2017 · 32 comments

Comments

@khagesh
Copy link

khagesh commented Jul 7, 2017

After I added sentry I am getting this error while building project.

PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/khagesh/Library/Developer/Xcode/DerivedData/CP-awyselqwjoqrjfeypmvugdxlaeoa/Build/Intermediates/CP.build/Debug-iphonesimulator/CP.build/Script-00DD1BFF1BD5951E006B06BC.sh
export ...
.........
/bin/sh -c /Users/khagesh/Library/Developer/Xcode/DerivedData/CP-awyselqwjoqrjfeypmvugdxlaeoa/Build/Intermediates/CP.build/Debug-iphonesimulator/CP.build/Script-00DD1BFF1BD5951E006B06BC.sh

env: node: No such file or directory

react-native: 0.44
react-native-sentry: 0.14.3
Xcode version: 8.3.3

I am using bitcode, but I don't think it should fail build.

I believe I followed all steps correctly of setting up sentry and checked sentry.properties file which has all things that are needed.
Any help will be much appreciated. Thanks!

@kumasento
Copy link

kumasento commented Jul 7, 2017 via email

@khagesh
Copy link
Author

khagesh commented Jul 7, 2017

yes, I have node.js 6.9.0

@khagesh khagesh closed this as completed Jul 7, 2017
@khagesh khagesh reopened this Jul 7, 2017
@kumasento
Copy link

As your error log suggests, the error came out from running /usr/bin/env node, which aims at getting the executable node program.

Maybe you can try to run /usr/bin/env node in a terminal and see how it goes.

@khagesh
Copy link
Author

khagesh commented Jul 7, 2017

I ran /usr/bin/env node in terminal and I can go to node command prompt. I typed console.log and it worked. I think something is missing with the paths of script that was set by sentry. It is just a guess.

Unfortunately I don't know much about build phase and how to add or debug custom scripts. If there is some path which I can follow to debug it. That would help me.

@grigored
Copy link

Spent few hours trying to solve this. It was weird that the file mentioned actually did exist (in your case /Users/khagesh/Library/Developer/Xcode/DerivedData/CP-awyselqwjoqrjfeypmvugdxlaeoa/Build/Intermediates/CP.build/Debug-iphonesimulator/CP.build/Script-00DD1BFF1BD5951E006B06BC.sh), but the paths in it were wrong.
In my case, I had react native 0.46.1.

See this pull request https://github.com/getsentry/react-native-sentry/pull/139/files
Basically what I did is replace in all the project (it was in around 3 files) node_modules/react-native/packager/react-native-xcode.sh with node_modules/react-native/scripts/react-native-xcode.sh

@khagesh
Copy link
Author

khagesh commented Jul 12, 2017

That is true for react native 0.46+. However, I don't think it is solution for the problem in general. Also, I am using react native 0.44 and unfortunately we are not planning an upgrade as of now. But the good news for me is that I solved my issue and also found out the seeming root cause after learning about custom build phases in xcode project.

Here is what I did to resolve my issue. Since sentry-cli is not a bash script, it is a node script. I added node in front of sentry-cli command and that resolved my issue with Bundle React Native Code And Images phase.

What react-native-sentry updated

export SENTRY_PROPERTIES=sentry.properties
export NODE_BINARY=node
../node_modules/sentry-cli-binary/bin/sentry-cli react-native xcode
../node_modules/react-native/packager/react-native-xcode.sh"

I changed it to add node

export SENTRY_PROPERTIES=sentry.properties
export NODE_BINARY=node
node ../node_modules/sentry-cli-binary/bin/sentry-cli react-native xcode
../node_modules/react-native/packager/react-native-xcode.sh"

After resolving this issue I faced same issue with Upload Debug Symbols to Sentry phase. So I added node in front of this script as well. However, this time I got the error that node command not found. It was strange since same script was working on Bundle phase. So, to resolve this issue I created a bash script of my own. Basically I sourced nvm again and set node in same script and then executed upload command. My script looks something like this

#!/bin/bash

# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
  . "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
  . "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
  eval "$("$HOME/.nodenv/bin/nodenv" init -)"
fi

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

# Run sentry cli script to upload debug symbols
$NODE_BINARY ../node_modules/sentry-cli-binary/bin/sentry-cli upload-dsym

And then I replaced build phase with something like this and everything started working.

export SENTRY_PROPERTIES=sentry.properties
export NODE_BINARY=node
../build-phase-scripts/upload-dsym.sh

Root cause for all of these issues that I strongly believe is how node is setup. If node is being setup using brew then default script provided by react-native-sentry will work. But if node is being setup with nvm, then we will face these issues. To confirm my theory I took help from my colleague who was using node using brew and without any change in build phase script his project was compiling just fine.

As to why I had to create a bash script for upload phase and not just adding node worked. I don't have the slightest of idea. I tried few possible reason but couldn't come up with strong reason. Anyway I have fixed it for me as of now. I don't know if we need to update docs or react-native-sentry link step to update script.

@wellyshen
Copy link

wellyshen commented Jul 12, 2017

I'm using nvm and I have the same issue during xCode building.

@grigored
Copy link

did you recently update to react native >0.46?

@wellyshen
Copy link

wellyshen commented Jul 13, 2017

@grigored Yes, I'm using 0.46.1. This's not my first time to meet this error, it also occurs on RN 0.45 and I'm stilling waiting for the official fixing :(

@benhowes
Copy link
Contributor

I've also found that using node through NVM was a problem and installed using brew. NVM node works fine under linux for android builds however

@ciriac
Copy link

ciriac commented Jul 20, 2017

@benhowes Thanks for this. In the end switching to node using Brew is what fixed it for me.

@HazAT
Copy link
Member

HazAT commented Jul 25, 2017

It seems this is the way to fix it if you are using nvm
Similar to what @khagesh posted
facebook/react-native#3935
I will close this for now since this is unrelated to Sentry, more about node/mac/Xcode

@HazAT HazAT closed this as completed Jul 25, 2017
@khagesh
Copy link
Author

khagesh commented Jul 25, 2017

I think we can update the docs to let people know what to do in case of nvm.

@HazAT
Copy link
Member

HazAT commented Jul 25, 2017

@khagesh Good idea, will do that. 👍
Thx

@wellyshen
Copy link

wellyshen commented Jul 25, 2017

Thanks writing the document will help us :)

@llaine
Copy link

llaine commented Jul 31, 2017

Doing brew install node solves the issue.

@hmatijevic
Copy link

@grigored thank you. This solved my issue.

@ChathuraP
Copy link

I also encountered the same issue and fixed and got help from this post.
This is actually what happen.
"react-native-xcode.sh" script is in two differant paths in two different react-native versions. and this script is referred in x-code build process. please take a look at the images. according to the react-native version, You has to find where is this script and update the path in Xcode then it will start to work.
In X-Code project
Project > target > Build Phases > Bundle React Native code and images
xcodepath

export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh

or

export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh

Path 1
YourProject > node_modules > react-native > scripts > react-native-xcode.sh
path1

or
Path 2
YourProject > node_modules > react-native > packager > react-native-xcode.sh
path2

I hope this will be more clear to all.

@trubi
Copy link

trubi commented Dec 6, 2017

Guys could you someone explain to me briefly what is that modification of "React Native Bundle" phase even necessary?
I am trying to separate sending sentry debug symbols from actual build because I don't need to upload these files to sentry during development, only on CI tool during production build.
So I removed sentry build phase from my project but then I still see after build that something is uploading to sentry which was very weird so I took a look into project file and realized that the bundle phase is also changed by sentry.
Any way how to completely separate sending symbolic files from actual build?

Original script in bundle phase:
export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh

After installing sentry:
export SENTRY_PROPERTIES=sentry.properties\nexport NODE_BINARY=node\n../node_modules/sentry-cli-binary/bin/sentry-cli react-native xcode ../node_modules/react-native/scripts/react-native-xcode.sh

@HazAT
Copy link
Member

HazAT commented Dec 6, 2017

So the step Upload Debug Symbols to Sentry uploads the dSYMs to Sentry, this one is optional but recommended for production builds.
We recommend using our https://github.com/getsentry/fastlane-plugin-sentry when you enable Bitcode so you download the debug symbols from iTunes Connect and upload them to Sentry.

The Bundle React Native code and images this step will change the react-native build process in that way that the packager generates sourcemaps which are necessary in order for us to symbolicate Javascript frames. By default, this does nothing in debug builds, only in release builds.

@asleepace
Copy link

asleepace commented Jan 15, 2018

For me I had to remove react-native-sentry by using react-native unlink react-native-sentry and following the uninstallation process. Then I also removed the dependency from my package.json and ran rm -rf node_modules && yarn.

Next I had to remove references to Sentry in my index.ios.js and app.js files, as well as all the references in my AppDelegate.m.

In the build phases of my project target I removed this line from "Bundle React Native code and images": ../node_modules/@sentry/cli/bin/sentry-cli react-native xcode and I also deleted the "Upload Debug Symbols to Sentry" section.

After building the project it was able to run again, so I re-added the Sentry package and went through the installation process with:

yarn add react-native-sentry
react-native link react-native-sentry

And it is now working, hope this helps!

@robvolk
Copy link

robvolk commented Feb 25, 2018

I'm upgrading from a pretty old version of Sentry and got it working by changing the path from /sentry-cli-binary/ to /@sentry/cli/ in project.pbxproj:

- shellScript = "export SENTRY_PROPERTIES=sentry.properties\nexport NODE_BINARY=node\n../node_modules/sentry-cli-binary/bin/sentry-cli react-native xcode ../node_modules/react-native/packager/react-native-xcode.sh";
+ shellScript = "export NODE_BINARY=node\n../node_modules/@sentry/cli/bin/sentry-cli react-native xcode ../node_modules/react-native/scripts/react-native-xcode.sh";

@miwillhite
Copy link

I ran into this after having updated node and realized (after way too long) that the run script was pointing to a node binary that no longer existed on my system 😂

@yammik
Copy link

yammik commented Nov 8, 2019

I'm upgrading from a pretty old version of Sentry and got it working by changing the path from /sentry-cli-binary/ to /@sentry/cli/ in project.pbxproj:

- shellScript = "export SENTRY_PROPERTIES=sentry.properties\nexport NODE_BINARY=node\n../node_modules/sentry-cli-binary/bin/sentry-cli react-native xcode ../node_modules/react-native/packager/react-native-xcode.sh";
+ shellScript = "export NODE_BINARY=node\n../node_modules/@sentry/cli/bin/sentry-cli react-native xcode ../node_modules/react-native/scripts/react-native-xcode.sh";

If you take this solution, just make sure you still have the config file in there. Otherwise, it'll yell at you to add the --org and --project and all that when you try to build. Essentially, the only offending part in the broken script is this: \nexport

@sinn1
Copy link

sinn1 commented Apr 20, 2021

This is still a problem. Another fix is here for NVM users: https://stackoverflow.com/a/50419734/8676545

Create symlink:

ln -s $(which node) /usr/local/bin/node

@pynner
Copy link

pynner commented Apr 24, 2021

For me, I renamed my Sentry project and ran into this error... after wasting my life on hunting node issues all it took was setting the defaults.project in sentry.properties to the new project name for it to work!

@elsurudo
Copy link

elsurudo commented Jun 25, 2021

Guys, there is still no clear solution as far I as I can see.

Create symlink:

ln -s $(which node) /usr/local/bin/node

I see that the above is now the "sanctioned" solution as per the docs, but it is not a good solution because I don't want to override node system-wide!

Any other ideas?

@elsurudo
Copy link

elsurudo commented Jun 25, 2021

FWIW what I ended up doing is modifying the last 2 lines of the build steps "Bundle react native node and images" AND "Upload debug symbols to Sentry" to:

export NODE_BINARY=/hard/coded/path/to/correct/node
/hard/coded/path/to/correct/node <PREVIOUS CONTENTS OF LAST LINE>

This forces the sentry CLI script to use the same version of node as my project.

IMO your docs should be updated with a better solution

@SMKH-PRO
Copy link

Facing the same issue in React Native 0.69.3

@ghost
Copy link

ghost commented Sep 5, 2022

Here is solution from Sentry docs

@asleepace
Copy link

The solution for our team was to specify the correct cli executable within our sentry.properties since we are using a mono-repo:

cli.executable=../../node_modules/@sentry/cli/bin/sentry-cli

@akhilesh-mourya
Copy link

This is still a problem. Another fix is here for NVM users: https://stackoverflow.com/a/50419734/8676545

Create symlink:

ln -s $(which node) /usr/local/bin/node

@sinn1 Big thanks.
I was trying on xcode15.3, Finally its working

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

No branches or pull requests