在 netlify 中部署 React 应用程序时出现问题
Issue in deployment of react app in netlify
- 我正在尝试在媒体 link 中提到的 netlify 中部署 React 应用程序:https://link.medium.com/nw9ZCh0lrV
- 所以我使用 express server 在生产模式下定义构建脚本和设置应用程序
- 构建脚本正在本地机器上创建并上传到 netlify 站点
- 显示消息部署成功
- 点击 URL link,它显示 GET 构建脚本请求的状态为 404
- netlify URL link: https://nostalgic-euclid-4f95ab.netlify.com
- 你们能帮我解决一下我的建议吗
- 下面附上应用截图
- 提供以下代码片段:
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
- 我正在尝试在媒体 link 中提到的 netlify 中部署 React 应用程序:https://link.medium.com/nw9ZCh0lrV
- 所以我使用 express server 在生产模式下定义构建脚本和设置应用程序
- 构建脚本正在本地机器上创建并上传到 netlify 站点
- 显示消息部署成功
- 点击 URL link,它显示 GET 构建脚本请求的状态为 404
- netlify URL link: https://nostalgic-euclid-4f95ab.netlify.com
- 你们能帮我解决一下我的建议吗
- 下面附上应用截图 - 提供以下代码片段:
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