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'));
});
的package.json
"scripts" : {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
create react app
中的常见错误是在homepage
文件中添加与您的站点位置不匹配的package.json
。完成生产构建后,资产将以域之后的任何路径的值为前缀。
https://nostalgic-euclid-4f95ab.netlify.com/codehangar/react-interview/static/js/main.7ab6795d.chunk.js
从损坏的(404)资产的路径看,您的主页值看起来像:
"homepage": "https://example.com/codehangar/react-interview",
如果要包含主页值,请确保它与您的网站网址相同。
在您的情况下,值应为:
"homepage": " https://nostalgic-euclid-4f95ab.netlify.com",
注意:*通常情况下,请将此设置保留在文件之外,直到您处于活动状态并设置域名为止。
也:
server.js
文件。