Gatsby-Strapi App returns Error: connect ECONNREFUSED 127.0.0.1:1337 on build

I am working on a Gatsby, Strapi.js, React, Graphql and Node js app and when i was about to deploy it to netlify, this error throw up:

7:13:35 PM: error "gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:
7:13:35 PM: connect ECONNREFUSED 127.0.0.1:1337
7:13:35 PM: 
7:13:35 PM: 
7:13:35 PM:   Error: connect ECONNREFUSED 127.0.0.1:1337
7:13:35 PM: 
7:13:35 PM: not finished source and transform nodes - 0.234s
7:13:35 PM: npm ERR! code ELIFECYCLE
7:13:35 PM: npm ERR! errno 1
7:13:35 PM: npm ERR! samuel-norton-portfolio@0.1.0 build: `gatsby build`
7:13:35 PM: npm ERR! Exit status 1
7:13:35 PM: npm ERR!
7:13:35 PM: npm ERR! Failed at the samuel-norton-portfolio@0.1.0 build script.
7:13:35 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
7:13:35 PM: npm ERR! A complete log of this run can be found in:
7:13:35 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-01-17T11_13_35_566Z-debug.log
7:13:35 PM: ​
7:13:35 PM: ────────────────────────────────────────────────────────────────
7:13:35 PM:   "build.command" failed                                        
7:13:35 PM: ────────────────────────────────────────────────────────────────
7:13:35 PM: ​
7:13:35 PM:   Error message
7:13:35 PM:   Command failed with exit code 1: npm run build
7:13:35 PM: ​
7:13:35 PM:   Error location
7:13:35 PM:   In Build command from Netlify app:
7:13:35 PM:   npm run build
7:13:35 PM: ​
7:13:35 PM:   Resolved config
7:13:35 PM:   build:
7:13:35 PM:     command: npm run build
7:13:35 PM:     commandOrigin: ui
7:13:35 PM:     publish: /opt/build/repo/public

Any idea how am I suppose to fix this? Please help!

1 Like

Why do you have localhost as your API endpoint? Isn’t the Strapi API endpoint somewhere else?