LoginSignup
20
8

More than 3 years have passed since last update.

ReactNativeプロジェクトをXcodeでビルドしたときに「node.jsが見つからない」とエラーが出た時の対処方法

Last updated at Posted at 2020-02-02

ReactNativeプロジェクトをXcodeでビルドしたときに「node.jsが見つからない(Can't find the 'node' binary)」とエラーが出ることがある。これはnode.jsを通常でない方法でインストールしている時、例えばhomebrew/nodebrew/nvmとかのパッケージマネージャ/バージョンマネージャを使っている場合とかに発生する。これを解決する。

エラーログ:

error: Can't find the 'node' binary to build the React Native bundle.  If you have a non-standard Node.js installation, select your project in Xcode, find  'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to an  absolute path to your node executable. You can find it by invoking 'which node' in the terminal.

環境

  • OS: Mohave 10.14.6
  • Xcode: 11.2
  • react-native: 0.61.5

解決策

エラーログに書いてある通り、Xcodeの、Build Phases' の 'Bundle React Native code and images' の NODE_BINARYをいじれば解決する。

ただ、これだと開発環境ごとにXcodeのプロジェクト設定を書き換える必要があるのでやや大変。自動化してもいいが、できれば書き換えなくて済む方法がいい。探したら、/usr/local/bin/nodeへ自分のnodeのsimlinkを張っておく方法1があった。

下記のコマンドを実行すればよい。

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

nodebrewであればこの解決策で動いたが、情報元のStackoverflowのコメントでnvmでは動かないという情報もあった2。動かない場合は、下記のようにXcodeのプロジェクト設定を書き換える解決策を使える。

xcodeprojを書き換える解決策

自分のnodeの場所を探して、

which node # -> /Users/n/.nodebrew/current/bin/node

ここへ書き込む

スクリーンショット 2020-02-02 22.38.08.png

スクリーンショット 2020-02-02 22.38.38.png

以上。

参考

20
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
8