firebase-tools: ECONNREFUSED ::1:4400 error even though firestore port and host are explicitly specified
[REQUIRED] Environment info
firebase-tools: 11.2.2
Platform: macOS
[REQUIRED] Test case
//firestore.spec.ts
import * as firebaseTesting from "@firebase/rules-unit-testing";
import { before } from "mocha";
before(async () => {
env = await firebaseTesting.initializeTestEnvironment({
projectId: "demo-project",
firestore: {
host: "127.0.0.1",
port: 8080,
rules: fs.readFileSync("firestore.rules", "utf8"),
},
});
});
//package.json
{
"name": "demo-project/security-rules",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test:mocha": "mocha test/*.spec.ts -r=ts-node/register --timeout 10000",
"test": "firebase emulators:exec --only firestore \"yarn test:mocha\"",
},
"dependencies": {
"firebase-tools": "11.2.2"
},
"devDependencies": {
"@firebase/rules-unit-testing": "2.0.3",
"@types/mocha": "9.1.1",
"firebase": "9.9.0",
"firebase-admin": "10.3.0",
"mocha": "10.0.0",
"ts-node": "10.8.2",
"typescript": "4.7.4"
}
}
[REQUIRED] Steps to reproduce
Run yarn run test
[REQUIRED] Expected behavior
Expected to exit with code 0
[REQUIRED] Actual behavior
Fails with FetchError: request to http://localhost:4400/emulators failed, reason: connect ECONNREFUSED ::1:4400
This error was introduced in release 11.0.0 and is not present in 10.9.2
Seems like it still tries to find emulators hub, even though host and port for firestore are explicitly specified.
Same error can be observed if a flag FIRESTORE_EMULATOR_HOST=127.0.0.1:8080 is passed.
Currently I solved this error in my project by locking firebase-tools to 10.9.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (9 by maintainers)
Links to this issue
Commits related to this issue
- fix: :bug: Fix firestore port ECONNREFUSED error solution reference https://github.com/firebase/firebase-tools/issues/4741 — committed to CAMPUS-NYCU/CAMPUS-backend by linyc0817 a year ago
@modosc I have a guess on what’s going on here – the error may be happening with our new port detection logic and somehow IPv6 isn’t available in your Docker network. But we’d still appreciate full logs to confirm this.
Also, if that’s the case, I think you can work around this by adding
loggingtoo (before we make the next release). Let us know if it works for you.i can confirm that adding both of these blocks fixes the issue for us:
i can also confirm the exact same log output as above. running docker on mac and there’s no ipv6 support.
@gkawin thank you! It worked on node18 by adding
NODE_OPTIONS=--dns-result-order=ipv4first.TRY THIS. In the
packages.json.I think Its from this issue. https://github.com/nodejs/node/issues/41145So, I added node runtime options in my
package.jsonfile like this. … “test”: “node --experimental-vm-modules –dns-result-order=ipv4first node_modules/jest/bin/jest.js”, “integration:test”: “firebase emulators:exec --only firestore,functions --project {PROJECT_ID} "pnpm test"” …The same issue happens inside a github action. Are there any fixes for that? Specifying the host to
0.0.0.0doesn’t help. It still saysconnect ECONNREFUSED ::1:8080PS: Downgrading to node 16 fixed the issue.
I have the same issue but is when I use the firestore emulator with the sdk admin in a NextJS app on Mac and adding this to my
firebase.jsonfix the issueFor me the problem was fixed by changing
host: localhosttohost: 127.0.0.1in myinitializeTestEnvironmentfunction call.From this:
to this:
It is a IPv6 issue within the Docker container for us too @yuchenshi
If someone is emulating functions as well, you have to define eventarc’s host as well to make it work again:
The full debug log:
👏🦾❤️
Upgrading to 11.3.0 fixed this for me! Thanks, @yuchenshi !
While we work on this, I think a better workaround than downgrading Firebase CLI is specifying the hub address explicitly using IPv4:
e.g. change the command:
Or in configuration: