あるSEのつぶやき・改

ITやシステム開発などの技術に関する話題を、取り上げたりしています。

React Nativeでreact-native init時のビルドエラー解消方法

React Native で 下記コマンドで、プロジェクトを作成しようとしました。

$ npx react-native init ReactNativeRealm --template react-native-template-typescript

なのですが、node のバージョンをいじったせいか、以下のビルドエラーが出力されるようになりました。

clang: warning: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX' [-Wincompatible-sysroot]
In file included from ../fsevents.cc:72:
../src/thread.cc:36:25: error: unknown type name 'ConstFSEventStreamRef'
void HandleStreamEvents(ConstFSEventStreamRef stream, void *ctx, size_t ...
                        ^
../src/thread.cc:36:108: error: unknown type name 'FSEventStreamEventFlags'
  ...stream, void *ctx, size_t numEvents, void *eventPaths, const FSEventStre...
                                                                  ^
../src/thread.cc:36:152: error: unknown type name 'FSEventStreamEventId'
  ...*eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventSt...
                                                                    ^
../src/thread.cc:54:3: error: unknown type name 'FSEventStreamContext'
  FSEventStreamContext context = { 0, ctx, NULL, NULL, NULL };
  ^
../src/thread.cc:56:3: error: unknown type name 'FSEventStreamRef'
  FSEventStreamRef stream = FSEventStreamCreate(NULL, &HandleStreamEvent...
  ^
../src/thread.cc:56:98: error: use of undeclared identifier
      'kFSEventStreamEventIdSinceNow'
  ...&HandleStreamEvents, &context, fse->paths, kFSEventStreamEventIdSinceNow...
                                                ^
6 errors generated.
make: *** [Release/obj.target/fse/fsevents.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/xxx/.nodenv/versions/10.16.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/Users/xxx/.nodenv/versions/10.16.0/bin/node" "/Users/xxx/.nodenv/versions/10.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/xxx/.npm/_npx/63422/lib/node_modules/react-native/node_modules/fsevents
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

いろいろ調べて、XCode Command Line Tools の再インストールもためしてみましたがダメでした。

再インストール方法は以下のコマンドの通りです。一応、やるなら自己責任でお願いします。

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

XCode Command Line Tools のアンインストールについては、以下の記事を参考にさせていただきました。

xanadu62.blogspot.com

どうしたものかと思っていると、OS を再起動しろという情報を見かけたので、Mac を再起動して再度プロジェクトを作成したらエラーが出力されないようになりました。

まさかの困った時の再起動で解決するとは。。。