Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Preparing Your Application for Deployment

Sean Gabriel Villoria
Sean Gabriel Villoria
8,515 Points

Heroku Local cannot find module /loader.js

This is my package file.

{
  "name": "heroku",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "engine": {
    "node": "14.x"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/gabbyvilloria/heroku.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/gabbyvilloria/heroku/issues"
  },
  "homepage": "https://github.com/gabbyvilloria/heroku#readme"
}

I get this error when I run "heroku local" command. What am I doing wrong?

$ heroku local
1:03:20 PM web.1 |  internal/modules/cjs/loader.js:1083
1:03:20 PM web.1 |    throw err;
1:03:20 PM web.1 |    ^
1:03:20 PM web.1 |  Error: Cannot find module 'C:\Users\Gabby\source\repos\heroku\app.js;'
1:03:20 PM web.1 |      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
1:03:20 PM web.1 |      at Function.Module._load (internal/modules/cjs/loader.js:923:27)
1:03:20 PM web.1 |      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
1:03:20 PM web.1 |      at internal/main/run_main_module.js:17:47 {
1:03:20 PM web.1 |    code: 'MODULE_NOT_FOUND',
1:03:20 PM web.1 |    requireStack: []
1:03:20 PM web.1 |  }
[DONE] Killing all processes with signal  SIGINT
1:03:20 PM web.1 Exited with exit code null

1 Answer

Hello

The loader cannot find app.js that you are specifying in your package.json or Procfile

{
...
   "main": "app.js",
...
}

However, it doesn't look like your starting anything as you have no dependencies to express. What is in app.js if it exists?

Heroku have a good starting tutorial that you may find useful before this video. Heroku Nodejs

Sean Gabriel Villoria
Sean Gabriel Villoria
8,515 Points

Hi Liam, thanks for the reply!

Weirdly enough I'm able to build successfully and run on heroku but the local testing fails.

Posting app.js below:

// Required
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const Chart = require('chart.js');

// vars
const router = express.Router();
let port = process.env.PORT;
if (port == null || port == "") {
  port = 3000;
}

const app = express();

app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use('/static', express.static('public'));

// Pug Enabled ?
app.set('view engine', 'pug');

// Routes
const mainRoutes = require('./routes');

app.get("/", function(req, res){
    res.render('chargingBoy');
    res.end();
});

app.get("/login", function(req, res){
    res.render('login');
    res.end();
});

app.get("/reports", function(req, res){
    res.render('reports');
    res.end();
});

app.post("/login", function(req, res){
    res.redirect("/");
    res.end();
})

// app.post("/", function(req, res){
//     res.redirect("/#batteryEncoding");
//     res.end();
// })

// Login Page
    // Accept Username
    // Accept Password
    // Verify credentials
    // Sign in

// Register Page
    // Accept username
    // Accept Password
    // Verify credentials
    // Admin approval
    // Create account

// Charging Boy dashboard
    // Encoding Section
        // Select Encoding Button
            // Battery Encoding
                // Pop up Form Generated
                    // Select Category -- UNIT IN/UNIT OUT/CHARGE IN/CHARGE OUT
                    // Encode Data -- VOLTAGE. UNIT. DRIVER. TIME. DATE.
                    // Store Data

            // Collection Encoding
                // Pop up Form Generated
                    // Encode Data
                    // Store Data

            // Akelco Reading
                // Pop up Form Generated
                    // Encode Data
                    // Store Data
    // Table of Records
        // Organize by latest swaps. Batteries Out. Pending Collectibles.
        // Read data set
        // Display by earliest OUT record.
        // DATE OUT / TIME OUT
        // DATE IN / TIME IN

// Admin dashboard
    // Main
        // Summary of Units Operating
        // Collection Report
            // Boundary
            // Battery Rent
            // Electricity Fee
        // Akelco Reading
            // Electricity Cost Estimate
                // Daily
                // Billing month-to-date

app.listen(port, function(){
    console.log(`The application is running on localhost:${port}!`)
});