在 netlify 中部署 React 应用程序时出现问题

Issue in deployment of react app in netlify

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


create react app 中的一个常见错误是在 package.json 文件中添加与您的站点位置不匹配的 homepage。进行生产构建后,资产会在域后添加任何路径的值。

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

从损坏的 (404) 资产的路径来看,您的主页值类似于:

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

如果您要包含主页值,请确保它与您的站点相同 URL。

在您的情况下,该值应为:

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

注意:* 通常,将此设置保留在文件之外,直到您上线并设置域。

还有:

  • 无需将构建文件夹存储在您的存储库 (.gitignore) 中。构建命令将在每次部署时替换它。
  • 您将不需要您提供的 server.js 文件。

尝试使用手动上传构建文件 在 netlify drop