ECONNREFUSED during Cloudflare Pages Build

I am trying to deploy a NextJS application using Cloudflare Pages. I get the following error when building with next build && next run:

	> Build error occurred
05:37:32.922	Error: connect ECONNREFUSED 127.0.0.1:80
05:37:32.922	    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
05:37:32.922	  type: 'Error',
05:37:32.922	  config: {
05:37:32.922	    url: '/category',
05:37:32.922	    method: 'get',
05:37:32.922	    headers: {
05:37:32.922	      Accept: 'application/json, text/plain, */*',
05:37:32.922	      'User-Agent': 'axios/0.19.2'
05:37:32.922	    },
05:37:32.922	    transformRequest: [ null ],
05:37:32.922	    transformResponse: [ null ],
05:37:32.922	    timeout: 0,
05:37:32.922	    xsrfCookieName: 'XSRF-TOKEN',
05:37:32.922	    xsrfHeaderName: 'X-XSRF-TOKEN',
05:37:32.922	    maxContentLength: -1
05:37:32.923	  },
05:37:32.923	  code: 'ECONNREFUSED'
05:37:32.923	}
05:37:32.970	Failed: build command exited with code: 1

Any idea how to troubleshoot this?

Hi @daniel30,

Could you try changing your build command to just next export?

Thanks for taking a moment to reply and offer this suggestion. I tried this but only get an error stating that I must first build the application:

	Error: Could not find a production build in the '/opt/buildhome/repo/.next' directory. Try building your app with 'next build' before starting the static export. https://err.sh/vercel/next.js/next-export-no-build-id

I see a potential fix here from @pier but am unsure where I should change localhost to
http://[::1]:8787

Oh btw I had an ECONNREFUSED 127.0.0.1 in Node and had to use http://[::1]:8787 instead.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.