Error: connect ECONNREFUSED 127.0.0.1:8000 on nuxtjs run generate

  • build log errors, screenshots, etc:
    ERROR Could not resolve routes
    FATAL connect ECONNREFUSED 127.0.0.1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)

  • Netlify instance name: quirky-swanson-ffb973.netlify.com

It seems to me like the build is not hitting my API. My API is currently only local and Iโ€™m curious if that is what is causing this issue?

When npm run generate is ran on my local frontend directory, it successfully generates the static site and dist directory that I am hoping to host through netlify.

Hiya, welcome to the forum. When I search for that error, it seems like something many other folks run into when generating their Nuxt.js sites. Have you asked here?
https://spectrum.chat/nuxt

Or maybe worth taking a look here (or similar issues):

Once you get that figured out, weโ€™d be more than happy to help you with deploying to Netlify!

Hey Jen, thank you for the reply.

I guess what brought me to the Netlify forums was due to this error only occurring during my build on Netlify, not on my local device.

Ah, I misunderstood! Could you please drop a full deploy log here so we can check out what happens before and after the error? The API not being deployed could definitely be a possible source of problems, but we need a bit more information.

Sure, here it is:

11:06:07 PM: Build ready to start
11:06:10 PM: build-image version: 9cade8af58c2cf3a17a1e9433d2e979149488837
11:06:10 PM: build-image tag: v3.3.5
11:06:10 PM: buildbot version: 2fd8f04962d5dbc77b79b9c2f5ab7a077e87376b
11:06:10 PM: Fetching cached dependencies
11:06:10 PM: Failed to fetch cache, continuing with build
11:06:10 PM: Starting to prepare the repo for build
11:06:10 PM: No cached dependencies found. Cloning fresh repo
11:06:10 PM: git clone https://github.com/CodyBontecou/mtgranksv3
11:06:11 PM: Preparing Git Reference refs/heads/master
11:06:12 PM: Starting build script
11:06:12 PM: Installing dependencies
11:06:13 PM: Downloading and installing node v10.19.0...
11:06:14 PM: Downloading https://nodejs.org/dist/v10.19.0/node-v10.19.0-linux-x64.tar.xz...
11:06:14 PM: 
###########################################
11:06:14 PM: #######                        70.2%
11:06:14 PM: 
###########################################
11:06:14 PM: ############################# 100.0%
11:06:14 PM: Computing checksum with sha256sum
11:06:14 PM: Checksums matched!
11:06:17 PM: Now using node v10.19.0 (npm v6.13.4)
11:06:17 PM: Attempting ruby version 2.6.2, read from environment
11:06:18 PM: Using ruby version 2.6.2
11:06:19 PM: Using PHP version 5.6
11:06:19 PM: Started restoring cached node modules
11:06:19 PM: Finished restoring cached node modules
11:06:19 PM: Installing NPM modules using NPM version 6.13.4
11:06:37 PM: > fibers@4.0.2 install /opt/build/repo/frontend/node_modules/fibers
11:06:37 PM: > node build.js || nodejs build.js
11:06:37 PM: `linux-x64-64-glibc` exists; testing
11:06:37 PM: Binary is fine; exiting
11:06:37 PM: > core-js@2.6.10 postinstall /opt/build/repo/frontend/node_modules/core-js
11:06:37 PM: > node postinstall || echo "ignore"
11:06:38 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
11:06:38 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
11:06:38 PM: > https://opencollective.com/core-js 
11:06:38 PM: > https://www.patreon.com/zloirock 
11:06:38 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
11:06:38 PM: > ejs@2.7.4 postinstall /opt/build/repo/frontend/node_modules/ejs
11:06:38 PM: > node ./postinstall.js
11:06:38 PM: Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
11:06:38 PM: > nuxt@2.10.2 postinstall /opt/build/repo/frontend/node_modules/nuxt
11:06:38 PM: > opencollective || exit 0
11:06:38 PM:                                      :-:
11:06:38 PM:                                    .==-+:
11:06:38 PM:                                   .==. :+- .-=-
11:06:38 PM:                                  .==.   :==++-+=.
11:06:38 PM:                                 :==.     -**: :+=.
11:06:38 PM:                                :+-      :*+++. .++.
11:06:38 PM:                               :+-      -*= .++: .=+.
11:06:38 PM:                              -+:      =*-   .+*: .=+:
11:06:38 PM:                             -+:     .=*-     .=*-  =+:
11:06:38 PM:                           .==:     .+*:        -*-  -+-
11:06:38 PM:                          .=+:.....:+*-.........:=*=..=*-
11:06:38 PM:                          .-=------=++============++====:
11:06:38 PM:                           Thanks for installing nuxtjs
11:06:38 PM:                  Please consider donating to our open collective
11:06:38 PM:                         to help us maintain this package.
11:06:38 PM:                            Number of contributors: 224
11:06:38 PM:                               Number of backers: 305
11:06:38 PM:                               Annual budget: $79,412
11:06:38 PM:                              Current balance: $20,572
11:06:38 PM:                  Donate: https://opencollective.com/nuxtjs/donate
11:06:40 PM: npm WARN
11:06:40 PM:  optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/watchpack/node_modules/fsevents):
11:06:40 PM: npm
11:06:40 PM:  WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
11:06:40 PM: npm WARN optional
11:06:40 PM:  SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
11:06:40 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
11:06:40 PM: added 1092 packages from 509 contributors and audited 10524 packages in 19.679s
11:06:40 PM: 14 packages are looking for funding
11:06:40 PM:   run `npm fund` for details
11:06:40 PM: found 14 moderate severity vulnerabilities
11:06:40 PM:   run `npm audit fix` to fix them, or `npm audit` for details
11:06:40 PM: NPM modules installed
11:06:41 PM: Started restoring cached go cache
11:06:41 PM: Finished restoring cached go cache
11:06:41 PM: unset GOOS;
11:06:41 PM: unset GOARCH;
11:06:41 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
11:06:41 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
11:06:41 PM: go version >&2;
11:06:41 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
11:06:41 PM: go version go1.12 linux/amd64
11:06:41 PM: Installing missing commands
11:06:41 PM: Verify run directory
11:06:41 PM: Executing user command: npm run generate
11:06:41 PM: > mtgranks@1.0.0 generate /opt/build/repo/frontend
11:06:41 PM: > nuxt generate
11:06:43 PM:  WARN  No .env file found in /opt/build/repo/frontend.
11:06:44 PM: โ„น Production build
11:06:44 PM: โœ” Builder initialized
11:06:45 PM: โœ” Nuxt files generated
11:06:46 PM: โ„น Compiling Client
11:07:18 PM: โœ” Client: Compiled successfully in 32.18s
11:07:18 PM: โ„น Compiling Server
11:07:38 PM: โœ” Server: Compiled successfully in 19.51s
11:07:38 PM: Hash: 89f652a0ea68d374b982
11:07:38 PM: Version: webpack 4.41.2
11:07:38 PM: Time: 32186ms
11:07:38 PM: Built at: 02/19/2020 5:07:18 AM
11:07:38 PM:                          Asset       Size  Chunks                                Chunk Names
11:07:38 PM: ../server/client.manifest.json     16 KiB          [emitted]
11:07:38 PM:        07b4ede0423a11adf418.js     46 KiB       0  [emitted] [immutable]         app
11:07:38 PM:        2cb4fd485f2066c9d317.js  309 bytes       4  [emitted] [immutable]         pages/set/_set/card/index
11:07:38 PM:        3b5e82807f208c5c80fc.js  475 bytes       2  [emitted] [immutable]         pages/index
11:07:38 PM:        4f023c0ad3dcc298f912.js      2 KiB       3  [emitted] [immutable]         pages/set/_set/card/_card
11:07:38 PM:        724493620c5011a8d823.js    182 KiB       1  [emitted] [immutable]         commons.app
11:07:38 PM:        741f8332b53cd5257199.js    540 KiB       7  [emitted] [immutable]  [big]  vendors.app
11:07:38 PM:                       LICENSES  571 bytes          [emitted]
11:07:38 PM:        a6ea007576d909c91f08.js    4.3 KiB       8  [emitted] [immutable]
11:07:38 PM:        b28ff691398c3288bdf5.js    3.9 KiB       5  [emitted] [immutable]         pages/set/_set/index
11:07:38 PM:        b5eae281ee02e63f5c7f.js    2.4 KiB       6  [emitted] [immutable]         runtime
11:07:38 PM:      icons/icon_120.5f6a36.png   4.68 KiB          [emitted]
11:07:38 PM:      icons/icon_144.5f6a36.png    5.8 KiB          [emitted]
11:07:38 PM:      icons/icon_152.5f6a36.png    6.1 KiB          [emitted]
11:07:38 PM:      icons/icon_192.5f6a36.png   7.83 KiB          [emitted]
11:07:38 PM:      icons/icon_384.5f6a36.png   18.1 KiB          [emitted]
11:07:38 PM:      icons/icon_512.5f6a36.png     20 KiB          [emitted]
11:07:38 PM:       icons/icon_64.5f6a36.png   2.35 KiB          [emitted]
11:07:38 PM:         manifest.614bbf3b.json  852 bytes          [emitted]
11:07:38 PM:  + 2 hidden assets
11:07:38 PM: Entrypoint app = b5eae281ee02e63f5c7f.js 724493620c5011a8d823.js 741f8332b53cd5257199.js 07b4ede0423a11adf418.js
11:07:38 PM: WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
11:07:38 PM: This can impact web performance.
11:07:38 PM: Assets:
11:07:38 PM:   741f8332b53cd5257199.js (540 KiB)
11:07:38 PM: Hash: 906898287ed817fdaa8d
11:07:38 PM: Version: webpack 4.41.2
11:07:38 PM: Time: 19509ms
11:07:38 PM: Built at: 02/19/2020 5:07:38 AM
11:07:38 PM:                   Asset       Size  Chunks                         Chunk Names
11:07:38 PM: 336c840d9aeba1081a4c.js   1.13 KiB       2  [emitted] [immutable]  pages/set/_set/card/_card
11:07:38 PM: 96d451e419ff7adc1067.js  310 bytes       3  [emitted] [immutable]  pages/set/_set/card/index
11:07:38 PM: ba47fc3e38dccf426104.js   3.12 KiB       4  [emitted] [immutable]  pages/set/_set/index
11:07:38 PM: dc41b337c51d8f4832f9.js  455 bytes       1  [emitted] [immutable]  pages/index
11:07:38 PM:               server.js    523 KiB       0  [emitted]              app
11:07:38 PM:    server.manifest.json  319 bytes          [emitted]
11:07:38 PM: Entrypoint app = server.js
11:07:38 PM:  ERROR  Could not resolve routes
11:07:38 PM:  FATAL  connect ECONNREFUSED 127.0.0.1:8000
11:07:38 PM:   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
11:07:38 PM: tput: No value for $TERM and no -T specified
11:07:38 PM:    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
11:07:38 PM:    โ”‚                                                โ”‚
11:07:38 PM:    โ”‚   โœ– Nuxt Fatal Error                           โ”‚
11:07:38 PM:    โ”‚                                                โ”‚
11:07:38 PM:    โ”‚   Error: connect ECONNREFUSED 127.0.0.1:8000   โ”‚
11:07:38 PM:    โ”‚                                                โ”‚
11:07:38 PM:    โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
11:07:38 PM: npm
11:07:38 PM:  ERR! code
11:07:38 PM:  ELIFECYCLE
11:07:38 PM: npm
11:07:38 PM: ERR! errno 1
11:07:38 PM: npm ERR! mtgranks@1.0.0 generate: `nuxt generate`
11:07:38 PM: npm ERR! Exit status 1
11:07:38 PM: npm ERR!
11:07:38 PM: npm ERR! Failed at the mtgranks@1.0.0 generate script.
11:07:38 PM: npm
11:07:38 PM: ERR! This is probably not a problem with npm. There is likely additional logging output above.
11:07:38 PM: npm ERR!
11:07:38 PM:  A complete log of this run can be found in:
11:07:38 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-02-19T05_07_38_524Z-debug.log
11:07:38 PM: Skipping functions preparation step: no functions directory set
11:07:38 PM: Caching artifacts
11:07:38 PM: Started saving node modules
11:07:38 PM: Finished saving node modules
11:07:38 PM: Started saving pip cache
11:07:38 PM: Finished saving pip cache
11:07:38 PM: Started saving emacs cask dependencies
11:07:38 PM: Finished saving emacs cask dependencies
11:07:38 PM: Started saving maven dependencies
11:07:38 PM: Finished saving maven dependencies
11:07:38 PM: Started saving boot dependencies
11:07:38 PM: Finished saving boot dependencies
11:07:38 PM: Started saving go dependencies
11:07:38 PM: Finished saving go dependencies
11:07:41 PM: Error running command: Build script returned non-zero exit code: 1
11:07:41 PM: Failing build: Failed to build site
11:07:41 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
11:07:41 PM: Finished processing build request in 1m31.336920536s

Thanks for sending that over. Based on the line that reads Entrypoint app = server.js, it looks like this app is trying to build a server when you run npm run generate and that wonโ€™t work on Netlify since we only deploy static sites:

It looks like Nuxt has some docs on โ€œgotchasโ€ when deploying to Netlify that may be helpful:

But the TL;DR is that frontend code that relies on server-side code will break because the server will never get set up. If itโ€™s possible for you to make this a static site, weโ€™d be happy to help you get it up and running :muscle:

1 Like

Hi, Iโ€™m getting the same error and @jenโ€™s reply doesnโ€™t really add up for me since we are just running nuxt generate which is the command for generating the static files. I donโ€™t know what that entrypoint app = server.js means but I believe it is completely standard behavior for nuxt generate.

My problem is related to the fact that I call a Netlify Function during build to generate my siteโ€™s routes dynamically.
In nuxt.config.js I have:

    generate: {
        routes: dynamicRoutes
    }

dynamicRoutes is defined at the top as:

import api from "./utils/api"
let dynamicRoutes = () => {
  return api.readAll().then((res) => {
    return res.data.map((list) => {
      return {
        route: '/lists/' + list.data.creator,
        payload: list.data
      }
    })
  })
}

api.readAll() is defined in api.js as:

const axios = require('axios');
const readAll = () => {
    return axios.get('/.netlify/functions/lists-read-all').then((response) => {
        return response.json()
    })
}

Iโ€™ve tried all flavors of tweaking such as using fetch, using the get directly in nuxt.config.js, etc etc.

I think the problem may be that functions are deployed after the build so they arenโ€™t accessible during build time. Could this make sense? Doesnโ€™t really seem practical though, that means we canโ€™t leverage the functions for fetching data to use for pre-rendering? Doesnโ€™t seem very static site friendly if so.

The functions are deployed only at build time, so you have to both:

  1. call previously deployed versions of the function
  2. use a full URL - GET /.netlify/functions/lists-read-all is notโ€ฆa valid URL - there is no sense during a build of โ€œyou are connected to (any) URLโ€, so you have to specify full network paths :slight_smile:

Is anyone getting this to work? Iโ€™m stumped to how no one else is having this issue when trying to deploy a nuxt app to netlify. How is there 0 documentation on this as well? Just seems crazy, Iโ€™d think everyone trying to do a deploy would be having this issue. How does nuxt NOT use a server to generate itโ€™s static files?

I think this has something to do with axios and either proxy or baseURL. Iโ€™ve tried a few things like turning the proxy on and off and setting a baseURL. If I give it a proxy then it gives me the ECONNREFUSED. If I try the baseURL itโ€™s giving me a 404. NPMโ€™s Axios doesnโ€™t give any other details including probably the most important bit which would be the dang LOCATION of the request that is return the 404. Iโ€™m going to remove the npm axios and reference it locally. Pretty annoying.

Was able to change the axios stuff so that I could see where the 404โ€™s were coming from. It does look like the deploy process is trying to run some async request for whatever reason. If I give it the baseURL of the API website it still has the url/api/route when it should be just url/route. I then gave it the baseURL of / and itโ€™s back to asking for requests from the netlify instance. I setup a _redirects file that is in my root that has

/* /index.html 200
/api/*  https://mydomain.com/:splat  200

No dice. I think I give up for now. I need to rethink how all this is working because I clearly donโ€™t understand why everyone isnโ€™t yelling about it. Seems so easy according to the documentation, but it just isnโ€™t happening for me.

Hey all,

Sorry I havenโ€™t replied but I was able to solve my problem. I ended up having to host my api online and use that as my baseURL. My guess is it has to do with how Netlify containerizes everything and thus localhost gets funky - they are trying to access their own localhost, not what I have on my computer.

I ended up using https://ngrok.com/ to quickly host my api online, generate the pages on deployment, then drop the ngrok server. Took about 3 minutes to setup and get going.