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

Can't create bundle: react-native-xcode.sh fails to call react-native #3948

Closed
heliumsoule opened this issue Nov 6, 2015 · 82 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@heliumsoule
Copy link

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!

  • react-native bundle --entry-file index.ios.js --platform ios --dev true --bundle-output /Users/[username]/Library/Developer/Xcode/DerivedData/firstP-diwselkaoasmusemncrzcyzygens/Build/Products/Debug-iphonesimulator/firstP.app/main.jsbundle --assets-dest /Users/[username]/Library/Developer/Xcode/DerivedData/firstP-diwselkaoasmusemncrzcyzygens/Build/Products/Debug-iphonesimulator/firstP.app
    ../node_modules/react-native/packager/react-native-xcode.sh: line 36: react-native: command not found
    Command /bin/sh failed with exit code 127
@greyexpert
Copy link

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.

@Jerrylingit
Copy link

as greyexpert's way,it works,but i still don't konw why……

@JonathanWi
Copy link

Same here, thanks @greyexpert, now to find a real solution :)

@jstowell29
Copy link

Experiencing the same issue... used @greyexpert workaround and was able to compile. Thanks

@sheets
Copy link

sheets commented Nov 6, 2015

@greyexpert work around worked for me as well.

@bartonhammond
Copy link

I had to add '/usr/local/bin' explicitly to ~/.bash_profile along w/ @greyexpert workaround

@timfpark
Copy link
Contributor

timfpark commented Nov 6, 2015

+1

@bartonhammond
Copy link

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?

@samsalisbury
Copy link

@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

@samsalisbury
Copy link

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.

@bartonhammond
Copy link

argh - @samsalisbury that was it. thanks

@samsalisbury
Copy link

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"
  ]
}

@samsalisbury
Copy link

UPDATE: I've found a few things out:

  • Even a .babelrc file containing only {} was causing the above failure.
  • I had a globally-installed babel-eslint 4.1.3 (RN has a dev dependency on 4.1.1). I removed this.
  • Now, the {} .babelrc file now did not cause a build failure, but the above posted one still did. Progress.
  • I bisected the .babelrc from above and isolated the issue to a single line whitelist entry:
{
  "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.

@samsalisbury
Copy link

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.

@samsalisbury
Copy link

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...

@AustinAmoruso
Copy link

==================== 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.

@heliumsoule
Copy link
Author

Thank you for the help @greyexpert That fix worked!

@ghost
Copy link

ghost commented Nov 7, 2015

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.

@imansyaefulloh
Copy link

Thank you for the help @greyexpert that fix worked for me.

@vood
Copy link

vood commented Nov 7, 2015

@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

@jwhitley
Copy link

jwhitley commented Nov 9, 2015

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. 😞

@jwhitley
Copy link

jwhitley commented Nov 9, 2015

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.

@diffractometer
Copy link

@vood your solution worked for me thanks!

@lineng1993
Copy link

thanks, it really worked

@mkonicek
Copy link
Contributor

mkonicek commented Dec 2, 2015

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

@mkonicek mkonicek changed the title Can't compile Xcode with new projects Can't create bundle: react-native-xcode.sh fails to call react-native Dec 2, 2015
@mkonicek
Copy link
Contributor

mkonicek commented Dec 2, 2015

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

@mkonicek
Copy link
Contributor

mkonicek commented Dec 2, 2015

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.

@mkonicek
Copy link
Contributor

mkonicek commented Dec 2, 2015

The fix is in 0.16.0-rc. Thank you @ide! 9a64f17

@gre
Copy link
Contributor

gre commented Dec 3, 2015

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

@jonolock91
Copy link

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.

@myusuf3
Copy link
Contributor

myusuf3 commented Dec 9, 2015

This isn't solved. I have been blocked from upgrading for a few because of this issue!

@mkonicek
Copy link
Contributor

mkonicek commented Dec 9, 2015

Have you guys tried nvm version > ~/.nvmrc?

@mkonicek
Copy link
Contributor

mkonicek commented Dec 9, 2015

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'?

@SpeCT
Copy link

SpeCT commented Dec 11, 2015

nvm version > ~/.nvmrc

This helps, thanks @gre 👍

@SunLn
Copy link

SunLn commented Dec 13, 2015

I have soloved this problem by this answer.
http://stackoverflow.com/a/29211118

@ChrisSki
Copy link

+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.

@liyaodong
Copy link

I'm using tj/n to manage node, same problem, fixed with source ~/.bash_profile & @SunLn solution hope a official solution .

@richarddewit
Copy link

+1 to @SunLn 👍

@backslash112
Copy link

+1 to @SunLn 👍, worked for me!

@chiho13
Copy link

chiho13 commented Jan 24, 2016

@greyexpert how do you add source ~/.bash_profile to the beginning of react-native-xcode.sh (where do you find this)

@frantic
Copy link
Contributor

frantic commented Jan 24, 2016

Hopefully the changes in #5518 will solve these problems once and for all.

@Kureev
Copy link
Contributor

Kureev commented Mar 2, 2016

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?

@frantic
Copy link
Contributor

frantic commented Mar 5, 2016

#5518 has landed and we no longer depend on global react-native-cli to build iOS projects.

@frantic frantic closed this as completed Mar 5, 2016
@WangMasterpro
Copy link

Selected “Run Script only when installing”。like this http://stackoverflow.com/a/29211118

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.