Issue in deployment of react app in netlify

て烟熏妆下的殇ゞ 提交于 2019-12-13 03:59:41

问题


  • 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"
  }



回答1:


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.


来源:https://stackoverflow.com/questions/55418728/issue-in-deployment-of-react-app-in-netlify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!