Webpack Proxy - ECONNREFUSED for proxy to api

on a fresh “hello” project I get:
Error occurred while proxying request localhost:8080/api/v2/status to http://localhost:8000/ [ECONNREFUSED]

on the webpack server in a development environment. The canisters run fine on the replica and if I go directly to the replica i.e “localhost:8000/api/v2/status” it works, same with “127.0.0.1:8080/api/v2/status” and if I change the webpack proxy to “127.0.0.1” or change the dfx.json to start the replica on “localhost” everything works fine … I just did not have to do that in the past.

Anyone have any thoughts on this one? I have Mac M1 …

Hello Forum - FYI, I also posted this in the Dfinity Discord and @kpeacock (Kyle) from the Dfinity team said that this behavior was most likely from a newer version of node.js.

So, I had 17.2 active and he said the SDK supports 12, 14, and 16 …

I unlinked 17, installed 16 and linked it …

for those that use “brew” on a Mac, I did this:

brew install node@16
brew unlink node
brew link --overwrite --dry-run node@16
#just to check I ran the --dry-run ... my machine wanted an "--overwrite" to complete
brew link --overwrite node@16

then started dfx and web pack dev server and it worked as before.

Thanks Kyle …

Updated this case in case others get stuck …

10 Likes

I really hope this bug doesn’t make it into a stable node.js release so that I don’t have the excuse anymore :grimacing:

1 Like

Recently ran into this same bug with NodeJS version v18.1.0.

Reverting to 16.xx.xx (stable) fixed it.

I’m a huge fan of nvm (also installable via brew) for switching between node versions.

1 Like

I’m not sure I followed this thread correctly, but maybe the problem can be explained by this:

1 Like

@kpeacock

This bug is now in a stable NodeJS release (18.12.1)

As previously mentioned, this issue occurs when using Node 18, but is fixed (does not occur) when using Node 16.

Is specific bug (in the post) with webpack, webpack plugins, or something else entirely? It would be nice to be able to spin up a dev-server without having to switch back to Node 16.



Additionally, it seems like there are a few agent-js features now (such as node compatibility flag and the native fetch implementation with createActor) that are using Node versions >= 18, so it might be time to fully support Node 18 :sweat_smile: :

Yes, node 18 is fully supported, and Paul is correct. Replace localhost with 127.0.0.1 in your webpack config and you should be good to go

6 Likes

I’m just now running into this issue with my app after adding a local ledger canister. I’ve replaced the localhost with 127.0.0.1 in my webpack config as well as binding that address as described in the thread linked by @paulyoung but I am unable to make calls or queries from my frontend canister to my backend canister, nor am I able to check the status at localhost:8080/api/v2/status. I’m able to make calls and queries to it from the console and Candid interface so I’m confused why it’s refusing connections from some actors.
This is using node 16.14.2

1 Like

The default port recently switched to 4943. Can you try localhost:4943/api/v2/status? On my machine, this works

1 Like

This worked, thank you so much!

1 Like

I get similar error too.

[webpack-dev-server] [HPM] Error occurred while proxying request localhost:8081/api/v2/status to http://127.0.0.1:4943/api/v2/status? [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

I even get something similar when i try to test http outcalls functions locally.

Already fixed by adding this to the dfx.json.

"networks": { "local": { "bind": "127.0.0.1:4943", "type": "ephemeral" } },