Why is production expecting connections on localhost?

I’m trying to deploy a React site and have set up my deploy commands like this:

Build command npm run build && npm install -g serve && serve -s build

I’m doing it that way because npm run build alone isn’t working and looking at the logs it encourages me to doa serve -s build. So I’m dutifully following directions. I’m just trying to get prod to work the way it works locally–everything works fine locally in dev!!

Here’s the logs–it seems to be expecting a local connection, and the build never “finishes” it just hangs.

7:32:20 PM: Build ready to start
7:32:21 PM: build-image version: 8e315e54bc4032a32e73290be556cde4f8348c12
7:32:21 PM: build-image tag: v2.8.2
7:32:21 PM: buildbot version: 76af94f42647b2019c5925a515cc8332b4883b85
7:32:22 PM: No cache source specified, skip fetching cache
7:32:22 PM: Starting to prepare the repo for build
7:32:22 PM: No cached dependencies found. Cloning fresh repo
7:32:22 PM: git clone https://github.com/team-refcode/refcode.org
7:32:26 PM: Preparing Git Reference refs/heads/master
7:32:28 PM: Starting build script
7:32:28 PM: Installing dependencies
7:32:29 PM: Downloading and installing node v10.24.1...
7:32:29 PM: Downloading https://nodejs.org/dist/v10.24.1/node-v10.24.1-linux-x64.tar.xz...
7:32:30 PM: 
#######
7:32:30 PM:                                     10.2%
7:32:30 PM: 
######################
7:32:30 PM: ################################################## 100.0%
7:32:30 PM: Computing checksum with sha256sum
7:32:30 PM: Checksums matched!
7:32:32 PM: Now using node v10.24.1 (npm v6.14.12)
7:32:32 PM: Attempting ruby version 2.6.2, read from environment
7:32:34 PM: Using ruby version 2.6.2
7:32:34 PM: Using PHP version 5.6
7:32:34 PM: Started restoring cached node modules
7:32:34 PM: Finished restoring cached node modules
7:32:34 PM: Installing NPM modules using NPM version 6.14.12
7:33:07 PM: > core-js@2.6.12 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
7:33:07 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:33:07 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
7:33:07 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
7:33:07 PM: > https://opencollective.com/core-js 
7:33:07 PM: > https://www.patreon.com/zloirock 
7:33:07 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
7:33:07 PM: > core-js@3.8.3 postinstall /opt/build/repo/node_modules/core-js
7:33:07 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:33:07 PM: > core-js-pure@3.8.3 postinstall /opt/build/repo/node_modules/core-js-pure
7:33:07 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:33:07 PM: > ejs@2.7.4 postinstall /opt/build/repo/node_modules/ejs
7:33:07 PM: > node ./postinstall.js
7:33:07 PM: Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
7:33:10 PM: npm
7:33:10 PM: WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
7:33:10 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7:33:10 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
7:33:10 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7:33:10 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.1 (node_modules/fsevents):
7:33:10 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7:33:10 PM: added 1942 packages from 760 contributors and audited 1945 packages in 34.325s
7:33:12 PM: 126 packages are looking for funding
7:33:12 PM:   run `npm fund` for details
7:33:12 PM: found 5880 vulnerabilities (170 moderate, 5710 high)
7:33:12 PM:   run `npm audit fix` to fix them, or `npm audit` for details
7:33:12 PM: NPM modules installed
7:33:12 PM: Started restoring cached go cache
7:33:12 PM: Finished restoring cached go cache
7:33:12 PM: unset GOOS;
7:33:12 PM: unset GOARCH;
7:33:12 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
7:33:12 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
7:33:12 PM: go version >&2;
7:33:12 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
7:33:12 PM: go version go1.12 linux/amd64
7:33:12 PM: Installing missing commands
7:33:12 PM: Verify run directory
7:33:12 PM: Executing user command: npm run build && npm install -g serve && serve -s build
7:33:13 PM: > refcode-app@0.1.0 build /opt/build/repo
7:33:13 PM: > react-scripts build
7:33:15 PM: Creating an optimized production build...
7:33:26 PM: Compiled successfully.
7:33:26 PM: File sizes after gzip:
7:33:26 PM:   49.62 KB  build/static/js/2.c8138d79.chunk.js
7:33:26 PM:   2.3 KB    build/static/js/main.d36518e3.chunk.js
7:33:26 PM:   1.4 KB    build/static/js/3.8bc9fc01.chunk.js
7:33:26 PM:   1.17 KB   build/static/js/runtime-main.8637bb46.js
7:33:26 PM:   901 B     build/static/css/main.943b65bf.chunk.css
7:33:26 PM: The project was built assuming it is hosted at /.
7:33:26 PM: You can control this with the homepage field in your package.json.
7:33:26 PM: The build folder is ready to be deployed.
7:33:26 PM: You may serve it with a static server:
7:33:26 PM:   npm install -g serve
7:33:26 PM:   serve -s build
7:33:26 PM: Find out more about deployment here:
7:33:26 PM:   https://cra.link/deployment
7:33:30 PM: /opt/buildhome/.nvm/versions/node/v10.24.1/bin/serve -> /opt/buildhome/.nvm/versions/node/v10.24.1/lib/node_modules/serve/bin/serve.js
7:33:30 PM: + serve@11.3.2
7:33:30 PM: added 78 packages from 39 contributors in 3.578s
7:33:31 PM: INFO: Accepting connections at http://localhost:5000

It’s not encouraging you to run the serve command. It’s just when you wish to preview your website after it’s built. The build process can’t determine if it’s a local build or a build on Netlify, so, it just says it assuming all builds are local.

Point being, you cannot run a live server on Netlify, so you should only run npm run build. When you say it’s not working, could you point to the problem that you’re facing? From the log above, there doesn’t seem to be any error.

1 Like

Thank you @hrishikesh . When things are going wrong sometimes I waste time barking up the wrong tree. It is good to get confirmation that all I need to do on the build is npm run build.

The problems I am having are that the React pages are all 404. I have a thread about that problem here (https://answers.netlify.com/t/trying-to-deploy-a-react-site-on-netlify-all-the-react-pages-are-404/38018/5) and I am still trying to find the answer.