LoginSignup
2
0

More than 5 years have passed since last update.

React NativeにRealm JSをインストールしようとした時に発生する2つのエラー対処(macOS)

Last updated at Posted at 2018-12-09

経緯

React Nativeを使う機会があり、macOS環境でRealm JSをインストールしたときに発生した2つのエラーへのわたしの対処を記載します(Windows環境ではエラーは発生しませんでした)。

開発環境

  • macOS Version: 10.14.1

ライブラリ

  • Ract Native Version: 0.57
  • Node Version: 11.2.0
  • Realm JS SDK Version: 2.21.0

エラーが発生する処理

  1. npm install realmを実行時したとき
  2. 上記を解消して、react-native run-iosを実行したとき

まず1.のエラー

$ npm install realm --save
:
In file included from ../src/node/node_init.hpp:25:
../src/node/node_function.hpp:41:19: error: no member named 'GetCallingContext' in 'v8::Isolate'; did you mean
      'GetCurrentContext'?
    if (!isolate->GetCallingContext().IsEmpty()) {
                  ^~~~~~~~~~~~~~~~~
                  GetCurrentContext
/Users/kin/.node-gyp/11.2.0/include/node/v8.h:7727:18: note: 'GetCurrentContext' declared here
  Local<Context> GetCurrentContext();
                 ^
1 error generated.
make: *** [Release/obj.target/realm/src/node/node_init.o] Error 1
:

Issueを読むと、Node11に未対応のために発生しているようです。現状で利用したいのでNodeのバージョンを10に落とすことにしました。

  • nodeのバージョンを変更
    わたしの環境では、nodeはHomebrewからインストールしたのでnodebrewを使ってバージョンを切り替えることにしました。

    https://github.com/hokaccha/nodebrew

    インストールされているnodeをアンインストール

    $ brew uninstall node --force
    

    nodebrewをインストール

    $ brew install nodebrew
    $ nodebrew setup
    $ nodebrew ls-remote
     インストール可能なバージョンを確認する
    

    現時点でv10の中で最も新しいバージョン10.14.1をインストール

    $ nodebrew install v10.14.1
    $ nodebrew ls
     インストールされたバージョンを確認する
    $ nodebrew use v10.14.1
    

    ~/.bash_profile等で実行パスに、$HOME/.nodebrew/current/binを追加する

    export PATH=$HOME/.nodebrew/current/bin:$PATH
    

    実行するNodeのバージョンを確認する

    $ node -v
    

    この時点で以下を実行してエラーが出ないはず。

    $ npm install realm --save
    $ react-native link realm
    
  • つぎは、2.のエラー

    上記まで対応して、react-native run-iosを実行するとコンソールに以下のエラーが表示されます。

    :
    RealmJS requires a node package manager (n or nvm).
    
    Command PhaseScriptExecution failed with a nonzero exit code
    
    ** BUILD FAILED **
    :
    

    今回は、nvmをインストールしました。

    $ brew install nvm
    

    これで2つ目のエラーの原因が解消されたので以下を実行してエラーがなくなりiOSアプリを起動できるようになるはずです。

    $ react-native run-ios
    
2
0
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
2
0