概要
- Firebase Emulatorを再起動した際に、『ポートが空いていないよ~』とエラーが発生する場合があります。
- その解決策をまとめました。
- (参考情報)ちなみに、Unit Testでエラーが発生し、強制終了した際にこの現象が発生することが度々ありました。
環境
Windows10
Node.js: 16.14.2
firebase-tools: 10.9.2
Visual Studio Code: 1.74.3
エラー発生状況
- まずは Firebase Emulator を起動します。
- FirestoreやStorageのデータをimportしない場合は、
--import=tests/firebase
は不要です。 - Firebase Emulator の公式リンク
- FirestoreやStorageのデータをimportしない場合は、
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"
TCP 127.0.0.1:8083 0.0.0.0:0 LISTENING 912
- 末尾の
912
がPIDなので、それを手がかりにしてさらに調べます。