0

I'm trying to deploy an nodejs app to heroku, and the build doesn't complete, it stops once server starts running. Here are the photos of of my app:

  1. The server

    const express = require('express');
    const bodyParser = require('body-parser');
    const path = require('path');
    const morgan = require('morgan');
    const app = express();
    require('dotenv').config();
    const port = process.env.PORT || 4000;

    // parse requests of content-type - application/x-www-form-urlencoded
    app.use(bodyParser.urlencoded({ extended: true }));

    // parse requests of content-type - application/json
    app.use(bodyParser.json());

    app.use(morgan('dev'));

    app.use(express.static('dist'));

    // database connection
    const db_conn = require('./models/mongoose-connection');
    db_conn.databaseConnection().catch((error) => console.error(error));

    // require routes
    app.use('/api', require('./routes/user'));

    // get routes from client-side
    app.get('/*', (req, res) => {
      res.sendFile(path.join(__dirname, '../dist', 'index.html'));
    });

    app.listen(port, () =>
      console.log('Express application booted, listening on %s.', port)
    );


  1. The package.json scripts are as follows:

      "scripts": {
        "server": "node server/app.js",
        "build": "webpack --mode production && npm run server",
        "start": "webpack-dev-server --open"
      },

  1. The app build process stops here and the build doesn't end.
bined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
remote:        Entrypoints:
remote:          main (383 KiB)
remote:              bundle.js
remote:        
remote:        
remote:        WARNING in webpack performance recommendations: 
remote:        You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
remote:        For more info visit https://webpack.js.org/guides/code-splitting/
remote:        Child HtmlWebpackCompiler:
remote:             1 asset
remote:            Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
remote:            [0] ./node_modules/html-webpack-plugin/lib/loader.js!./public/index.html 498 bytes {0} [built]
remote:        
remote:        > blesser@1.0.0 server /tmp/build_b4b117004ecd6958331b75eea3eb8d3a
remote:        > node server/app.js
remote:        
remote:        Express application booted, listening on 4000.
remote:        Connection Established

  • This question seems to be duplicated. See https://stackoverflow.com/questions/49348365/webpack-4-size-exceeds-the-recommended-limit-244-kib It is a problem with your webpack configuration, as the first line of your output states (in point 3). – Sergio Jul 08 '20 at 08:27

1 Answers1

0

Add Procfile at the root of the application with the following contents:

web: node server/app.js

This will be run once the deployment is done.