首页 > 解决方案 > 在 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.

标签: javascriptnode.jsreactjsheroku

解决方案


推荐阅读