LoginSignup
10
5

More than 5 years have passed since last update.

React Nativeは Node.jsで実行されていなかった

Posted at

React Nativeで本格的に開発して2ヶ月くらい経ちますが今日React NativeがNode.jsの実行環境で動作していないことを知りました。

ことの発端はNode.jsの標準モジュールであるurlを使おうとimport * as url from 'url'と書いたことです。
するとビルド時に以下のエラーが出力されるようになりました。

Error: Unable to resolve module `url` from `/Users/user544/dev/mimizuku_client/react_project/App.tsx`: Module `url` does not exist in the Haste module map

でまぁ、React Nativeのbundlerあたりの問題かと思って、よくあるキャッシュ削除の手順とか実行したんですが、一向に解決できないわけです。
いろいろググっていると https://stackoverflow.com/questions/39046429/react-native-unable-to-resolve-module-fs を発見。

同じく標準モジュールのfsを使おうとしてエラーになっているひと。
回答を見るとReact Native アプリはNode.js環境で実行されないよ。コンパイルとかパッケージャーとして使ってるだけ。 とのこと :rolling_eyes:

React Native applications do not run in the Node.js environment (it is only used by the packager to actually serve and compile your application bundle).

いやーハマったハマった。
これで心置きなく npm install url --save できる。

10
5
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
10
5