I recently updated node to 5.0.0 and react-native won't compile in Xcode. Previous projects still work though. Does anyone have any thoughts? Thank you!
I have the same problem.
I found that XCode $PATH differs from terminal $PATH and it doesn't include path of nvm nodes (~/.nvm/versions/...).
I have temporary fixed it by adding source ~/.bash_profile to the beginig of react-native-xcode.sh but there should be a better solution.
as greyexpert's way,it works,but i still don't konw why……
Same here, thanks @greyexpert, now to find a real solution :)
Experiencing the same issue... used @greyexpert workaround and was able to compile. Thanks
@greyexpert work around worked for me as well.
I had to add '/usr/local/bin' explicitly to ~/.bash_profile along w/ @greyexpert workaround
+1
I created new project (react-native @0.14.0 and changing index.ios.js does not update in iOS simulator w/ Cmd+R. Anyone else experience this w/ this newest release?
@bartonhammond I had to kill the initial packager that was started after react native init ... and start it again with npm start to get it to work in general.. However it's now failing in the way reported by the OP
For me, the Xcode build script failure as originally reported started after I upgraded a 0.13.2 project to 0.14.0. I then created a new 0.14.0 project from scratch, and it all worked. I took my original index.os.js, styles.os.js, and dependencies from package.json (including 2 libraries with native components) into the fresh new project, and then this issue started again. I have not yet tried @greyexpert's trick.
Here is the relevant bit of the build log from Xcode:
DEST=/Users/xxx/Library/Developer/Xcode/DerivedData/AwesomeProject-gttzgacpenhrxsfurdqdxmuyymsa/Build/Products/Debug-iphonesimulator/AwesomeProject.app
+ react-native bundle --entry-file index.ios.js --platform ios --dev true --bundle-output /Users/xxx/Library/Developer/Xcode/DerivedData/AwesomeProject-gttzgacpenhrxsfurdqdxmuyymsa/Build/Products/Debug-iphonesimulator/AwesomeProject.app/main.jsbundle --assets-dest /Users/xxx/Library/Developer/Xcode/DerivedData/AwesomeProject-gttzgacpenhrxsfurdqdxmuyymsa/Build/Products/Debug-iphonesimulator/AwesomeProject.app
/Users/xxx/AwesomeProject/node_modules/react-native/node_modules/promise/lib/done.js:10
throw err;
^
TypeError: Cannot assign to read only property 'undefined' of [object Object]
at /Users/xxx/AwesomeProject/node_modules/react-native/private-cli/src/bundle/buildBundle.js:22:5
at tryCallTwo (/Users/xxx/AwesomeProject/node_modules/react-native/node_modules/promise/lib/core.js:45:5)
at doResolve (/Users/xxx/AwesomeProject/node_modules/react-native/node_modules/promise/lib/core.js:171:13)
at new Promise (/Users/xxx/AwesomeProject/node_modules/react-native/node_modules/promise/lib/core.js:65:3)
at buildBundle (/Users/xxx/AwesomeProject/node_modules/react-native/private-cli/src/bundle/buildBundle.js:18:10)
at Array.bundle (/Users/xxx/AwesomeProject/node_modules/react-native/private-cli/src/bundle/bundle.js:19:10)
at Object.run (/Users/xxx/AwesomeProject/node_modules/react-native/local-cli/cli.js:68:13)
at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:27:7)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
Command /bin/sh failed with exit code 1
UPDATE I don't know if it's relevant, but I'm using lots of bleeding edge ES7 features. If that might be relevant to someone who understands the problem let me know and I'll post my .babelrc etc.
argh - @samsalisbury that was it. thanks
np @bartonhammond
UPDATE: I have isolated the problem in my case to my .babelrc. Simply adding this file to a brand new (verified working) RN 0.14.0 project causes the above failure. I suspect this may related to some global dependencies I've installed and forgotten about which pick up on this, I'm going to try & isolate it.
Here's my .babelrc for completeness:
{
"whitelist": [
"es6.modules",
"es6.arrowFunctions",
"es6.blockScoping",
"es6.classes",
"es6.destructuring",
"es6.parameters",
"es6.properties.computed",
"es6.properties.shorthand",
"es6.spread",
"es6.templateLiterals",
"es7.trailingFunctionCommas",
"es7.objectRestSpread",
"flow",
"react",
"es7.classProperties",
"es7.asyncFunctions",
"es7.decorators",
"regenerator",
"utility.inlineEnvironmentVariables"
]
}
UPDATE: I've found a few things out:
{} was causing the above failure.babel-eslint 4.1.3 (RN has a dev dependency on 4.1.1). I removed this.{} .babelrc file now _did not_ cause a build failure, but the above posted one still did. Progress.{
"whitelist": [
"utility.inlineEnvironmentVariables"
]
}
The above .babelrc file plus a brand new react-native init ... project comprises a complete repro of the issue as far as I can tell. Anyone else here want to see if they get the same results?
I'm gonna see if I can live without that for now, and with RN's 4.1.1 version of babel-eslint...
NOTE: Though all of the above the packager never once showed issues.
UPDATE: Removing the "utility.inlineEnvironmentVariables" whitelist entry from .babelrc from my original upgraded project resolved the original issue. Everything is fixed for me, I hope some of this is helpful for anyone else with these issues.
Just realised my issue wasn't the same as the OP's, oops, I've been running on Node 4.2.1 rather than 5, and had a different error from the same script...
==================== SOLUTION ====================
@greyexpert has the right idea the pathing of the script is wrong either add source ~/.bash_profile or .zshrc or what ever you use these days to get the path set up correctly.
Thank you for the help @greyexpert That fix worked!
Only adding source ~/.bash_profile was able to fix this for me. I didn't have a .babelrc at all, and this was a brand new project on the latest version of the react native tools.
Thank you for the help @greyexpert that fix worked for me.
@greyexpert great solution thanks. One thing to add: in my case it was not exactly source ~/.bash_profile but source ~/.zshrc because i'm using oh-my-zsh. The path to the file to change is /path/to/the/project/node_modules/react-native/packager/react-native-xcode.sh
It's a bad idea in general to source one's bash/zsh environment into any automation system. I've done a lot of work with highly repeatable automation environments (complex dev-to-production & devops VM environments, build systems, etc.), and nvm/rvm are an absolute plague there. Neither of those tools can run without a shell using their injected runtime functions as a proxy. This is outright impossible to do sanely and/or repeatably with many tools. Shell functions are absolutely the wrong means to this end.
Instead, I use and highly recommend ndenv for node (and its namesake rbenv for Ruby users). ndenv manages node versions via a directory of shim scripts, ~/.ndenv/shims. For each node bin script available, ndenv creates a matching shim script. The shim dir is then placed on PATH. When a script is run, e.g. react-native, the shim asks ndenv which node version is active then proxies to the original bin script using the correct node environment. This works very reliably just by adding one directory to PATH, no complex shell injection required.
HOWEVER: I get the same error using ndenv because <_expletive deleted_> Xcode 7.1 wholly overwrites a PATH set as a user-defined project setting. E.g. I can add a setting for PATH as $PATH:~/.ndenv/shims, see that the shims dir is correctly expanded and added to the iOS default PATH in the Xcode settings UI... but all of that is thrown away in PATH in the environment dump when react-native-xcode.sh is run. I describe that problem in more detail over on StackOverflow.
This would allow for an easy and robust solution, but so far, I've been unable to determine whether there's any mechanism as of Xcode 7.1 that allows PATH to be augmented. :disappointed:
For completeness, I've also inquired about the Xcode PATH behavior over on the Apple Developer Forums, but have yet to get any responses as of this writing.
@vood your solution worked for me thanks!
thanks, it really worked
Another temporary workaround can be found here. https://github.com/facebook/react-native/issues/3946#issuecomment-154446396
Please try react-native 0.14.2, which should include a fix for this.
Not sure what's caused it. But running 14.2 _had_ fixed this issue for me. I tried installing react-native-icons, then I got the error again, uninstalling did nothing to fix the error.
On a side note: It seems that I cannot install any plugin to my app now without it throwing an error about unknown modules.
Ignore me for a bit. I'll do some more digging. Something is causing it to all trip over every now and then. I'll take regular snapshots to see what's changing at the point of error and open an issue - if I can recreate it - with more details.
It does still not work for me, getting the error: Command /bin/sh failed with exit code 8. Just to double check: I use v14.2 if it says "react-native": "^0.14.2" in my package.json after a new react-native init, correct? The only workaround that work for me is #3946 (comment)
.
Done a little digging into this. It can also occur while the xcode script is running if there are any references in the JS code to images that aren't corrected located in the base project. It doesn't warn that the image is the problem, or load the project and then highlight the issue. it just fails with no meaningful error message.
@greyexpert thanks, it works for me.
add source ~/.bash_profile before case "$CONFIGURATION" in...
@MossP I seem to have the same issue with a supposedly missing image. Even though it is correctly added in xcode like in all other projects. Did you find a workaround perhaps?
@BobD Not yet. I was just testing the new version but I will have to tackle the issue soon so I'll keep you posted. Let me know if you find a way around it too.
@MossP , @BobD I could confirm that issue appear just after importing a single image to XCode project... Have no idea what causing it.
UPD. Just figured out, that the problem was in recent changes in 0.14.2. My images was referenced incorrectly. Documentation explains it all. https://facebook.github.io/react-native/docs/images.html#content. I guess developers just hate to update docs, and that is why this page https://facebook.github.io/react-native/docs/image.html#content should be deprecated...
I just stopped using old:
source={require('image!myIcon')}
and started using new:
<Image source={require('./my-icon.png')} />
@ide Can we please re-open this issue? I have 0.14.2 installed and I am still getting the error Command /bin/sh failed with exit code 8. What info would you need from me? (btw. adding source ~/.bash_profile does not work for me either)
@Thorbenandresen Could you check the error log inside of xcode and report back what the error is on?
@christopherdro thanks - is this here enough do you need the whole log?
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/thorbenandresen2/Documents/@Code - React Native/NewProject/node_modules/react-native/node_modules/babel-core/lib/api/register/node.js:214:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/thorbenandresen2/Documents/@Code - React Native/NewProject/node_modules/react-native/cli.js:15:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Command /bin/sh failed with exit code 8
what version of Node are you using?
@ide v4.0.0 - too old?
4.0 is fine -- mainly 0.8-0.12 are problems.
node 5.0.0 with react-native 0.14.2 and the issue is persisting. Currently, the only fix I've found is @greyexpert's source ~/.bash_profile at the top of react-native-xcode.sh
It all works fine on my coworker's computer using react-native 0.13.1
@lasergoat Are your co-workers all using node 5.0.0 also?
I also upgraded to 5.0.0 and I also still have the issue on 0.14.2. The source ~/.bash_profile does still not work for me.
I'm experiencing the same error with my Xcode build after upgrading to 0.14.2, but not straight away it happened after a few hours of tinkering and I don't know why. Where do I add source ~/.bash_profile to react-native-xcode.sh I can't figure it out.
When I removed from my build phases:
Bundle React Native code and images
/bin/sh
../node_modules/react-native/packager/react-native-xcode.sh
it then worked, but I assume this is needed for the new image changes in 0.14.2 for iOS and Android.
@christopherdro I think I missed out an important line (see first line) in my error log from above:
/Users/thorbenandresen2/Documents/@Code - React Native/rn_starterv4/node_modules/react-native/local-cli/cli.js:56
const setupEnvScript = /^win/.test(process.platform)
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/thorbenandresen2/Documents/@Code - React Native/rn_starterv4/node_modules/babel-core/lib/api/register/node.js:214:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/thorbenandresen2/Documents/@Code - React Native/rn_starterv4/node_modules/react-native/cli.js:15:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Command /bin/sh failed with exit code 8
I am also wondering why the source ~/.bash_profile workaround is not working for me.
1) First of all, how do I know which file I need to source in react-native-xcode.sh? I have seen many different examples in this and the related issues, like source ~/.zshrc or ~/.bash or ~/bashrc to name a few.
2) And then, what need to be in that sourced file? Currently my ~/.bash_profile looks like this
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=$HOME/local/bin:$PATH
...and my ~/bashrc looks like this:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PATH=$HOME/local/bin:$PATH
export NVM_DIR="/Users/thorbenandresen2/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Update: I deleted my .bash_profile and created a new one from scratch. Now this 0.14.2 project compiles fine, even without adding source ~/.bash_profile to the react-native-xcode.sh.
HOWEVER, when I react-native init a new project, the error re-surfaces and I have no clue how I can fix that. This is very mysterious to me.
Update: nope, doesnt work!
Update: My bad, creating a new empty bash file didn't fix it either. I have currently no way to run the react-native-xcode.sh with RN 0.14.2 , RN CLI 0.1.7 & XCode 7.1.1. No clue what else I could try...
Hi guys, hope this helps someone, I solved it by changing my shell to usr/local/bin/fish in XTerm's Build Phases, since it's /bin/sh by default, and I'm running Fish.

fixed:react-native-xcode.sh 45 react-native:command not found
1.add source ~/.bash_profile to the begining of react-native-xcode.sh(path/to/your/app/node_modules/react-native/packager/react-native-xcode.sh)
if .bash_profile does not exist in your home/name then :touch .bash_profile
2.add export PATH=/usr/local/bin:$PATH to .bash_profile
still not working for me
I solved my problem: Turns out that I had Node 5.1 installed with Mac-Installer, while the NVM was still using an (too) old version of node. So I updated NVM and then installed the new version with nvm install 5.1. Now everything works fine and there is no need to source the .bash_profile any longer.
Can be closed for my sake.
@MossP It seems the issue with the missing native image asset was simply due to an syntax change in the react native update http://facebook.github.io/react-native/docs/images.html
I have the same issue,but I can't fixed the issue.Pls help!!!
It is worth mentioning, that react-native command (as in line 36: react-native: command not found) is provided by react-native-cli npm package. All the PATH manipulations will not help unless react-native-cli is installed.
@BobD Thanks. I had to have a look at this today. That helped. Thank you
I have little context on this (would ask @frantic but he's on vacation). I see that people have posted multiple workarounds. Is anyone up for sending a PR to fix this in a generic way?
I am hitting the same issue. Switching Node versions (4.2.2 -> 4.1.1 -> 5.1) doesn't help. I couldn't get it work with source ~/.bash_profile adding to the top of the script either.
for some reason I can't get the sourcing working anymore (I used to have it working) in 0.15.x :(
I basically can't run any RN project in XCode.
Why does react-native bundle call react-native-xcode.sh? Oh I see, the react-native bundle you posted wasn't actually what you ran on the command line but it's the output from Xcode.
And I assume you added that to Xcode based on the upgrading guide: https://facebook.github.io/react-native/docs/upgrading.html
It is worth mentioning, that react-native command (as in line 36: react-native: command not found) is provided by react-native-cli npm package. All the PATH manipulations will not help unless react-native-cli is installed.
Yes, you can't use React Native without the CLI. See https://facebook.github.io/react-native/docs/getting-started.html#quick-start
The documentation on upgrading says this at the bottom:
If you installed Node via nvm, you might experience "react-native: command not found". See #3974 for workaround and #4015 for the fix.
The fix is in 0.16.0-rc. Thank you @ide! https://github.com/facebook/react-native/commit/9a64f17de84e50a4fc60f1b96168aa61925934a8
I was still having the problem because my nvm wasn't set to a default version.
Make sure you have a .nvmrc file defined somewhere in your path. For instance in your ~ (home).
You can bootstrap it like this:
nvm version > ~/.nvmrc
I've upgraded to version 0.16.0 but I'm still getting the error Command /bin/sh failed with exit code 1 to do with the Bundle React Native code and images.
It's trying to run this file
/Users/myusername/Library/Developer/Xcode/DerivedData/PamperPadProject-ftjvdxryfwxhqtaunsduatskifbv/Build/Intermediates/PamperPadProject.build/Debug-iphonesimulator/PamperPadProject.build/Script-00DD1BFF1BD5951E006B06BC.sh
I followed the route and it does exist though.
This isn't solved. I have been blocked from upgrading for a few because of this issue!
Have you guys tried nvm version > ~/.nvmrc?
Does this happen always or only when building a release version from Xcode? Have little context here.
Do you hit this when doing react-native init, open the project in Xcode and click 'Run'?
nvm version > ~/.nvmrc
This helps, thanks @gre :+1:
I have soloved this problem by this answer.
http://stackoverflow.com/a/29211118
+1 to @SunLn.
node: 4.2.3
npm: 2.14.7
nvm: 0.29.0
react-native-cli: 0.1.7
I'm not sure what it all means since I don't know the iOS environment very well. If there are any repercussions with this method moving forward I'd love to hear them so I can save myself any issues in the future.
I'm using tj/n to manage node, same problem, fixed with source ~/.bash_profile & @SunLn solution hope a official solution .
+1 to @SunLn :+1:
+1 to @SunLn :+1:, worked for me!
@greyexpert how do you add source ~/.bash_profile to the beginning of react-native-xcode.sh (where do you find this)
Hopefully the changes in https://github.com/facebook/react-native/pull/5518 will solve these problems once and for all.
Well, the initial issue is about react-native: command not found. Installing react-native-cli globally should solve the problem, right?
What do I miss, @mkonicek?
react-native-cli to build iOS projects.Selected “Run Script only when installing”。like this http://stackoverflow.com/a/29211118
Most helpful comment
I have the same problem.
I found that XCode
$PATHdiffers from terminal$PATHand it doesn't include path of nvm nodes (~/.nvm/versions/...).I have temporary fixed it by adding
source ~/.bash_profileto the beginig ofreact-native-xcode.shbut there should be a better solution.