javascript - 在 Heroku 上部署 React 应用程序时出现应用程序错误
问题描述
我创建了一个 React 应用程序并使用 webpack 来捆绑它。现在我正在尝试在 heroku 上部署应用程序。构建成功,但是当我尝试打开链接时,我得到“应用程序错误”。是否有必要在您的反应应用程序的根级别上拥有 server.js 文件才能在 heroku 上进行 delpoy。
我已经修改了我的 webpack,我认为它很好,但仍然是同样的错误。
//这是我的 webpack.common.js
const webpack = require("webpack");
module.exports = {
entry: "./index.jsx",
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: { presets: ["@babel/env"] }
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
resolve: { extensions: ["*", ".js", ".jsx"] },
output: {
path: path.resolve(__dirname, "dist/"),
publicPath: "/dist/",
filename: "bundle.js"
},
plugins: [new webpack.HotModuleReplacementPlugin()]
}
// webpack.dev.js
const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.common');
module.exports = merge(common, {
mode:'development',
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, "public/"),
port: 3000,
publicPath: "http://localhost:3000/dist/",
hot: true
}
});
I expect the app to get deployed on heroku but I am getting application error.
解决方案
推荐阅读
- wordpress - 我正在开发一个 WordPress 主题并使用自定义字段。我面临以下问题
- eclipse - Eclipse 2021-03 - 从 Tomcat 8 更新到 Tomcat 9,现在我无法让 bat 成功运行
- pdb - Docker环境下Django项目失败时如何自动断点
- ruby-on-rails - 在 Rails 中从 S3 下载文件的动态链接
- python - 如何在 Python 中将李克特量表响应转换为数值
- r - R中的分组条形图用于数据框的矩阵
- python-3.x - 我需要将什么类型传递给表对象的 multiprocessing.Value
- c# - 如何重构此代码以搜索 BindingList 的多个属性?
- javascript - useEffect 和 useState 不重新渲染 React 组件
- javascript - 具有功能的 A 帧检查变量并根据值显示不同的 gltf