0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Firebase EmulatorでのポートNGエラーの解決方法

Last updated at Posted at 2023-02-01

概要

  • Firebase Emulatorを再起動した際に、『ポートが空いていないよ~』とエラーが発生する場合があります。
  • その解決策をまとめました。
  • (参考情報)ちなみに、Unit Testでエラーが発生し、強制終了した際にこの現象が発生することが度々ありました。

環境

Windows10
Node.js: 16.14.2
firebase-tools: 10.9.2
Visual Studio Code: 1.74.3

エラー発生状況

  • まずは Firebase Emulator を起動します。
my-project
firebase emulators:start --import=tests/firebase
  • するとこんなエラーが発生する場合があります。
!  emulators: Support for Java version <= 10 will be dropped soon in firebase-tools@11. Please upgrade to Java version 11 or above to continue using the emulators.
i  emulators: Starting emulators: auth, firestore, hosting, pubsub, storage
!  emulators: It seems that you are running multiple instances of the emulator suite for project hino-solutions. This may result in unexpected behavior.
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
!  firestore: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "firestore": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Firestore Emulator, port taken.
  • Error: Could not start Firestore Emulator, port taken. と書いてある通り、port確保ができなくてFirestoreの起動を失敗したみたいです。

ポート番号調査

  • 確保したかったFirestoreのport番号を調べます。
  • firebase.jsonのfirestoreの設定値を確認します。
my-project/firebase.json
{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "storage": {
    "rules": "storage.rules"
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "firestore": {
      "port": 8083
    },
    "hosting": {
      "port": 5000
    },
    "pubsub": {
      "port": 8085
    },
    "storage": {
      "port": 9199
    },
    "eventarc": {
      "port": 9299
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  }
}

my-project/firebase.json の抜粋です
...
    "firestore": {
      "port": 8083
    },
...
  • 8083 ですね。

該当portは何に使われているか調査

  • コマンドプロンプトで以下のコマンドを入力します。
    • 8083 の部分に任意の調べたいport番号を記載してください。
netstat -nao | find "8083"
  • するとこんな応答が出ます。(内容は、人によって異なると思います。)
    image.png
TCP  127.0.0.1:8083  0.0.0.0:0  LISTENING  912
  • 末尾の 912 がPIDなので、それを手がかりにしてさらに調べます。

PIDを手がかりに調査

  • タスクマネージャーを起動します。

  • 詳細タブを選択します。
    image.png

  • 犯人は java.exe でした。

  • 右クリック -> タスクの終了 で強制終了させます。

  • 以上です。お疲れ様でした。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?