Netlify Functions - Create React App - ECONNREFUSED

I am working on a simple web app using Create React App. I’ve just started integrating Netlify Functions, which I have used on a Gatsby project before. I have installed the Netlify Dev CLI locally and tried to call netlify functions:invoke login to invoke my login function, which is located under the netlify/functions folder. This returns an error: ECONNREFUSED and 404 Not Found. The build command finds the function, but invoke does not. I have also tried to publish the site, and get the same error when calling from the app using the path /.netlify/functions/login or http://localhost:8888/.netlify/functions/login.

I have noticed that my functions are being served on port 8888, while my site (when running under netlify dev) is using port 3000. Are these meant to be the same, or are the requests to the functions proxied in some way?

I have tried adding a netlify.toml file pointing to the function path, but I get the same error (see below).

❯ netlify functions:invoke login
◈ “port” flag was not specified. Attempting to connect to localhost:8888 by default
› Error: Ran into an error invoking your function: request to http://localhost:8888/.netlify/functions/login failed, reason: connect ECONNREFUSED ::1:8888


  functions = "netlify/functions/"

Folder structure:


I’m sure when I have used this previously, that it worked out of the box without any special configuration.

Just to confirm, the invoke command only works when the CLI is already running (that is you’ve ran netify dev). Could you confirm if that’s the case?

Thanks for the response. I’ve double-checked this, and I can confirm that when I run netlify dev and then run the invoke with the port specified (the one that the functions are noted as running under when running netlify dev) then the invoke does work.

However, invoking the function from the web app using the path /.netlfiy/functions/login still doesn’t work.

I’ve also just tried setting the functionsPort flag when running netlify dev as 8888 to see if the invoke works without a port being specified, given that’s the default port it uses. This does not work - it still gets a connection refused error when invoking.

The difference when calling the function from the web app is that I get a 404 error.

This sounds oddly weird. Does your app run correctly on localhost:8888?

It doesn’t seem to be running on port 8888 - it’s just the functions:invoke that tries to hit that port by default. Here is the output when running netlify dev locally:

❯ netlify dev
◈ Netlify Dev ◈
◈ Ignored general context env var: LANG (defined in process)
◈ Loaded function login.
◈ Functions server is listening on 38557
◈ Starting Netlify Dev with Create React App

> federation-points@0.1.0 start
> react-scripts start

(node:10464) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:10464) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...

Compiled successfully!

You can now view federation-points in the browser.

  Local:            http://localhost:3000
  On Your Network:

Note that the development build is not optimized.
To create a production build, use npm run build.

webpack compiled successfully

I haven’t done much configuration - just created the app using Create React App and then retroadded Netlify CLI and the function. You can view the code on GitHub, if that helps.

Are you using Node 17+ by any chance?

Yes, I absolutely was! I did not realise it didn’t work with v17. I’ve been using that in my own development on other projects recently and it’s been a while since I used the Netlify CLI, so it didn’t even occur to me to check on compatibility. Thanks for your help!

1 Like