在 OS X 上使用 ndenv 设置 React Native [英] Setup of React Native using ndenv on OS X

查看:29
本文介绍了在 OS X 上使用 ndenv 设置 React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 7.1 中设置新的 React Native iOS 项目时遇到了 PATH 困难.我正在尝试使用

I'm running into PATH difficulty setting up a new React Native iOS project in Xcode 7.1. I'm trying to use ndenv to manage node versions, which means ~/.ndenv/shims needs to be on PATH. To that end, I have PATH set as a user-defined project setting as $PATH:~/.ndenv/shims. The Xcode settings UI shows the correct expanded PATH value.

Yet the project, generated by react-native init, still fails to build. The custom build script fails to find react-native:

../node_modules/react-native/packager/react-native-xcode.sh: line 36: react-native: command not found

react-native is installed correctly, but the environment variables dump in the build output makes clear that ~/.ndenv/shims isn't on PATH. My PATH settings don't appear in the build environment. However, if I set a random user-defined setting (e.g. FOOBAR=baz), that does correctly show up in the build environment.

That result plus further inspection of PATH in the build environment makes clear that Xcode is overriding PATH somewhere along the line.

So in order of preference:

  • How do I correctly append to PATH for a custom build script in Xcode 7?
  • Alternatively, what's the best (least hacky?) way of getting ndenv-managed npm modules on PATH for the build script?

Modifying react-native-xcode.sh is out of the question, since that's a part of the external react-native npm module.

UPDATE 1

As a temporary workaround, I've bailed on ndenv and installed node via homebrew. This puts react-native on the (apparently-hardcoded) Xcode path at /usr/local/bin, and works to get the build running. I'm not going to submit or accept this as a solution, since it doesn't allow the repeatable control of node versions that ndenv does.

解决方案

This issue was effectively fixed when facebook/react-native#5518 landed. react-native-xcode.sh now respects a NODE_BINARY environment variable that tells it where to find node on the build system. Under your app's target, see Build Phases > Bundle React Native code and images and set the shell script code to:

export NODE_BINARY=$HOME/.ndenv/shims/node
../node_modules/react-native/packager/react-native-xcode.sh

If your node is in a different location, change the value of NODE_BINARY to suit your installation. Here's a screencap from Xcode 7.1 to aid navigation:

这篇关于在 OS X 上使用 ndenv 设置 React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆