'Angular/Firebase/Node js app on Heroku - Error: Cannot find module '/app/src/server.js'

I've created an Angular project with Firebase Firestore as a database, using parts of the Angular Fire library. I'm currently attempting to deploy this project with Heroku and keep running into the same error:

Error: Cannot find module '/app/src/server.js'

I have a procfile My procfile. It only contains

web: node src/server.js

This is my directory tree: The server.js file is inside the src file, so I don't know why the output says it can't find it. I was following this tutorial to publish the app on heroku, so the server.js file contains the following:

    function requireHTTPS(req, res, next) {
        // The 'x-forwarded-proto' check is for Heroku
        if (!req.secure && req.get('x-forwarded-proto') !== 'https') {
            return res.redirect('https://' + req.get('host') + req.url);
        }
        next();
    }

    const express = require('express');
    const app = express();
    app.use(requireHTTPS);
    app.use(express.static('./dist/[my project name]'));
    app.get('/*', function(req, res) {
        res.sendFile('index.html', {root: 'dist/[my project name]/'}
    );
    });

I honestly have no idea what the server.js file should/shouldn't contain, where it should be, etc.; any education would be appreciated.

My package.json file:

{
  "name": "[my project name]",
  "version": "0.0.0",
  "engines": {
    "node": "14.15.1",
    "npm": "6.14.9"
  },
  "scripts": {
    "ng": "ng",
    "start": "node src/server.js"
  },

I've been trying to fix this problem for the past 4 hours; I keep seeing information about the procfile, but I'm almost certain mine is completely correct.

A heroku log snippet is below. Heroku successfully deploys the app, but when its actually accessed the page just says "application error".

2022-03-02T13:46:08.030891+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:952:19)
2022-03-02T13:46:08.030891+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:88:18)
2022-03-02T13:46:08.030891+00:00 app[web.1]: at Object.<anonymous> (/app/src/server.js:9:21)
2022-03-02T13:46:08.030892+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2022-03-02T13:46:08.030892+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2022-03-02T13:46:08.030892+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:928:32)
2022-03-02T13:46:08.030892+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2022-03-02T13:46:08.030893+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {  
2022-03-02T13:46:08.030893+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-02T13:46:08.030894+00:00 app[web.1]: requireStack: [ '/app/src/server.js' ]
2022-03-02T13:46:08.030894+00:00 app[web.1]: }
2022-03-02T13:46:08.179139+00:00 heroku[web.1]: Process exited with status 1
2022-03-02T13:46:08.253601+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-02T13:46:36.000000+00:00 app[api]: Build succeeded
2022-03-02T13:51:45.689236+00:00 heroku[router]: at=error code=H10 desc="App crashed" 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source