Skip to content

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

Closed
@khagesh

Description

@khagesh

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!

Activity

kumasento

kumasento commented on Jul 7, 2017

@kumasento
khagesh

khagesh commented on Jul 7, 2017

@khagesh
Author

yes, I have node.js 6.9.0

reopened this on Jul 7, 2017
kumasento

kumasento commented on Jul 7, 2017

@kumasento

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

khagesh commented on Jul 7, 2017

@khagesh
Author

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

grigored commented on Jul 11, 2017

@grigored

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

khagesh commented on Jul 12, 2017

@khagesh
Author

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

wellyshen commented on Jul 12, 2017

@wellyshen

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

grigored

grigored commented on Jul 12, 2017

@grigored

did you recently update to react native >0.46?

wellyshen

wellyshen commented on Jul 13, 2017

@wellyshen

@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

benhowes commented on Jul 14, 2017

@benhowes
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

ciriac commented on Jul 20, 2017

@ciriac

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

HazAT

HazAT commented on Jul 25, 2017

@HazAT
Member

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

22 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @elsurudo@miwillhite@HazAT@benhowes@ciriac

        Issue actions

          Build fails on Xcode. Run custom shell script 'Bundle React Native code and images' · Issue #141 · getsentry/sentry-react-native