Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)

前端 未结 24 2291
梦如初夏
梦如初夏 2020-11-22 05:42

I have my first node.js app (runs fine locally) - but I am unable to deploy it via heroku (first time w/ heroku as well). The code is below. SO doesn\'t let me write so much

24条回答
  •  萌比男神i
    2020-11-22 06:29

    I Use ReactJs, If you want upload to heroku add this in your webpack.config.js

    Because if not add you will have error

    Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

    //webpack.config.js add code like that
    
    const HtmlWebPackPlugin = require("html-webpack-plugin");
    const MiniCssExtractPlugin = require("mini-css-extract-plugin");
    var server_port = process.env.YOUR_PORT || process.env.PORT || 5000;
    var server_host = process.env.YOUR_HOST || "0.0.0.0";
    
    module.exports = {
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
              loader: "babel-loader"
            }
          },
          {
            test: /\.css$/,
            use: [MiniCssExtractPlugin.loader, "css-loader"]
          }
        ]
      },
      devServer: {
        disableHostCheck: true,
        contentBase: "./ dist",
        compress: true,
        inline: true,
        port: server_port,
        host: server_host
    
      },
      plugins: [
        new HtmlWebPackPlugin({
          template: "./src/index.html",
          filename: "index.html"
        }),
        new MiniCssExtractPlugin({
          filename: "[name].css",
          chunkFilename: "[id].css"
        })
      ]
    };
    

提交回复
热议问题