1
  • I am trying to deploy react application in netlify as referred from the medium link: https://link.medium.com/nw9ZCh0lrV
  • so I used express server to define build scripts and setting application in production mode
  • Build scripts are creating in local machine and uploaded in netlify site
  • It shows message as successful deployment
  • on clicking on URL link, it shows status to GET request for build scripts as 404
  • netlify URL link: https://nostalgic-euclid-4f95ab.netlify.com
  • can you guys help me where I have done mistake with your suggestion
  • attached application screenshots below -providing code snippets below:

server.js

const express = require('express');
const favicon = require('express-favicon');
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname,'build')));
app.get('/*', function (req, res) {
 res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

packagae.json

"scripts" : {
 "start": "react-scripts start",
 "build": "react-scripts build",
 "test": "react-scripts test",
 "eject": "react-scripts eject"
 }

enter image description here
enter image description here

talves
14.4k5 gold badges42 silver badges64 bronze badges
asked Mar 29, 2019 at 13:39

3 Answers 3

5

A common mistake in a create react app is to add a homepage in the package.json file that does not match your site location. Once you do a production build, the assets are prepended with the value of any path after the domain.

https://nostalgic-euclid-4f95ab.netlify.com/codehangar/react-interview/static/js/main.7ab6795d.chunk.js

From the look of the path of the broken (404) asset, your homepage value looks something like:

 "homepage": "https://example.com/codehangar/react-interview",

If you are going to include a homepage value, make sure it is the same as your site URL.

In your case the value should be:

 "homepage": " https://nostalgic-euclid-4f95ab.netlify.com",

Note:* Typically, leave this setting out of the file until you are live and have your domain set.

Also:

  • No need to store the build folder in your repository (.gitignore). The build command will replace it on each deploy.
  • You will not need the server.js file you supplied.
answered Mar 30, 2019 at 22:24
Sign up to request clarification or add additional context in comments.

3 Comments

@talves...thanks a lot for your reply...its working...your explanation is really good...
@talves...I am also trying to deploy java spring boot app in AWS, but facing issue in deployment process which I have posted in stack overflow and its link: stackoverflow.com/questions/55346085/… .... If possible, can you kindly look into it and provide your suggestions for it
confirmed. package.json "homepage" was the culprit. deleted it all together
0

Try using manual uploading the build file on netlify drop

answered Mar 24, 2021 at 6:57

Comments

0

Place _redirects file in public directory and in package.json file try changing homepage value as this worked for me

answered Jun 2, 2023 at 15:53

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.