1 javascript npm reactjs netlify create-react-app
服务器.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'));
});
Run Code Online (Sandbox Code Playgroud)
包.json
"scripts" : {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
Run Code Online (Sandbox Code Playgroud)
a 中的一个常见错误是在文件中create react app添加与您的站点位置不匹配的 a。进行生产构建后,资产将在域后面添加任何路径的值。homepagepackage.json
https://nostalgic-euclid-4f95ab.netlify.com/codehangar/react-interview/static/js/main.7ab6795d.chunk.js
从损坏的 (404) 资源的路径来看,您的主页值类似于:
"homepage": "https://example.com/codehangar/react-interview",
Run Code Online (Sandbox Code Playgroud)
如果您要包含主页值,请确保它与您的网站 URL 相同。
在您的情况下,该值应该是:
"homepage": " https://nostalgic-euclid-4f95ab.netlify.com",
Run Code Online (Sandbox Code Playgroud)
注意: *通常,请将此设置保留在文件之外,直到您上线并设置域为止。
还:
server.js您提供的文件。| 归档时间: |
|
| 查看次数: |
2444 次 |
| 最近记录: |