Issue with Heroku deployment: Express module not detected

I'm currently facing an issue while trying to deploy my Node.js app that includes some getter and setter functions. Despite selecting the Node.js environment on Heroku and providing all necessary environment variables, I keep encountering errors related to Express.

Jul 24 10:18:04 PM  node:internal/modules/cjs/loader:949
Jul 24 10:18:04 PM    throw err;
Jul 24 10:18:04 PM    ^
Jul 24 10:18:04 PM  
Jul 24 10:18:04 PM  Error: Cannot find module 'express'
Jul 24 10:18:04 PM  Require stack:
 - /opt/render/project/src/index.js
Jul 24 10:18:04 PM      at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
Jul 24 10:18:04 PM      at Module._load (node:internal/modules/cjs/loader:787:27)
Jul 24 10:18:04 PM      at Module.require (node:internal/modules/cjs/loader:1012:19)
Jul 24 10:18:04 PM      at require (node:internal/modules/cjs/helpers:102:18)
Jul 24 10:18:04 PM      at Object.<anonymous> (/opt/render/project/src/index.js:1:17)
Jul 24 10:18:04 PM      at Module._compile (node:internal/modules/cjs/loader:1112:14)
Jul 24 10:18:04 PM      at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
Jul 24 10:18:04 PM      at Module.load (node:internal/modules/cjs/loader:988:32)
Jul 24 10:18:04 PM      at Module._load (node:internal/modules/cjs/loader:834:12)
Jul 24 10:18:04 PM      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
Jul 24 10:18:04 PM    code: 'MODULE_NOT_FOUND',
Jul 24 10:18:04 PM    requireStack: [ '/opt/render/project/src/index.js' ]
Jul 24 10:18:04 PM  }
Jul 24 10:18:04 PM  
Jul 24 10:18:04 PM  Node.js v18.5.0

Package.json

{
  "name": "linktree_back",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js --ext js",
    "dev": "nodemon index.js --exec 'npm start -s"
  },
  "dependencies": {
    "@sendgrid/mail": "^7.7.0",
    "axios": "^0.27.2",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.20.0",
    "dotenv": "^16.0.1",
    "express": "^4.18.1",
    "express-validator": "^6.14.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^6.3.5",
    "mongoose-unique-validator": "^3.1.0",
    "node": "^18.5.0"
  },
  "keywords": [
    "example",
    "heroku"
  ],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^2.0.19"
  }
}

To import Express in index.js, I use this line of code:

const express = require("express");

along with the server setup

mongoose
  .connect(process.env.MONGO_URL)
  .then(() => {
    app.listen(process.env.PORT || 5000);
  })
  .catch((err) => {
    console.log(err);
  });

Answer №1

Ensure you have all the necessary dependencies installed by running npm install to check for any missing packages specified in your package.json file. Afterward, proceed to deploy your application to Heroku. If you are aware that you are only lacking the express module, you can manually install it using the command:

npm install express

The reason your app is unable to locate the express module is because it has not been installed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unlocking the Power of Node.js in Complex Business Scenarios

While I understand that this question may be ambiguous, I am seeking answers nonetheless. I am in the process of setting up a JSON-based WebService to provide information to multiple websites and mobile apps. Given that we frequently run CPU intensive My ...

Having difficulties collaborating with routers

I have a router setup in my app.js file, but for some reason it's not functioning as expected. The request is going to: /user This is the code snippet from app.js: var user = require('./routers/user') app.use('/user', user) And ...

Struggling with transferring a variable from Express to EJS

I am encountering a problem that I can't seem to solve. Every time I attempt to view this in my browser, an error message is displayed. ReferenceError: /views/login.ejs:14 12| <h1> 13| Value: >> 14| <span id="val"><%= v ...

Managing relationships within TypeORM's single table inheritance using a base class for targeting relations

In my application, I aim to provide users with notifications in the form of news items of various types. The relationship between User and NewsItem needs to be one-to-many, with NewsItem serving as a base class for different types of news items. Below is ...

Managing the parallel processing of messages with ConsumerGroup

Currently, I am utilizing the kafka-node ConsumerGroup to retrieve messages from a specific topic. However, upon consuming a message, a call to an external API is necessary, and it can potentially take up to a second for a response to be received. My goal ...

Experience the sound together

My goal is to stream audio from a NodeJS server to a client's browser using socket.io and socket.io-stream. I have successfully implemented the code, but I am facing one issue. Here is the code snippet for the server.js file: const express = require( ...

Calculating distance in Cloudant: A Comprehensive Guide

Trying to tackle a challenge here. The scenario involves receiving the client's current location through an API managed by a Node.js app. We have a Cloudant database storing a variety of coordinates (a couple thousand, to be precise). The goal is to ...

Tips for leveraging the power of Vuetify in Angular versions 7 and 9

I am looking to integrate Vuetify UI Components with Angular using VueCustomElement. While I have successfully integrated Angular and VueCustomElement, adding Vuetify has resulted in errors such as missing $attr and $. However, I am determined to add eithe ...

There appears to be a timeout issue with the handshake in Node.js version 6.9.1 when connecting to MySQL

While using 'mysql' and 'express-myconnection', I noticed that everything works perfectly when running on localhost or some internet connections with AWS server. However, when trying to access it from other internet connections with the ...

Transfer images from an Android device to a Node.js server by utilizing AsyncHttpClient

I am looking to send images from an android app to a node.js server for storage in MongoDB on the server side. I am using AsyncHttpClient to make a POST request. This is what my code looks like: On Android -> RequestParams param = new RequestParams(); p ...

Uh oh! Encountered an issue: Module 'shrink-ray' not found. Attempted to install but ran into another

node version required for this project is 8.9.4. The npm version used is 5.6.0. This project already exists, and after installing the necessary node modules, I encountered an error when running npm start. In an attempt to resolve this issue, I executed n ...

What is the best method for extracting (or recording) the data from the Response object in an Express application?

I'm looking to capture the data that is being sent. I have experience setting up middleware to capture request and response headers. Specifically, I want to capture the sent data itself. This is what I've tried: var express = require('exp ...

Problem importing npm module with Meteor 1.3

I've been trying to follow the guide for using npm packages in Meteor 1.3, particularly focusing on installing the moment npm module. However, I can't seem to work it out despite its simplicity. Every time I attempt to use the package in the cli ...

Struggling to include an array of objects in react useState and encountering the error message 'Attempting to render objects directly in React is not valid (object found with keys {})'

I am facing an issue while trying to use React useState to add an array of objects. The error message I keep receiving is "Objects are not valid as a React child (found: object with keys {})". Here is the code snippet from my app.js file: const [users, ...

Using Node.js and Express.js to redirect users after a successful data insertion

I am currently developing a CRUD application in Nodejs/Expressjs using EJS as the templating engine. Within my "views" folder, I have created a subfolder named "login" which contains several .ejs files. All of my .ejs files are located within the views fo ...

Error: Unable to access properties of an undefined variable (looking for 'findAll')

Need help with stack overflow issue! I'm encountering this problem: const { Model } = require('sequelize'); module.exports = (sequelize, DataTypes) => { class Skill extends Model { /** * Helper method for defining associations ...

Error: The function rtdb.initStandalone does not exist

As someone who is new to both Node and Firebase, I have encountered an error that doesn't seem to be documented online. The specific error occurs when attempting to load Firebase Database through Firebase Admin: TypeError: rtdb.initStandalone is not ...

Leveraging Javascript Modules within a Typescript Vue Application

The issue at hand I've encountered a problem while attempting to integrate https://github.com/moonwave99/fretboard.js into my Vue project. My initial approach involved importing the module into a component as shown below: <template> <div&g ...

Having trouble transmitting data with axios between React frontend and Node.js backend

My current challenge involves using axios to communicate with the back-end. The code structure seems to be causing an issue because when I attempt to access req.body in the back-end, it returns undefined. Here is a snippet of my front-end code: const respo ...

Tips for formatting the key-value pairs in a JSON object

As a newcomer to nodejs, I have managed to successfully retrieve data from the database and display it as a REST API in key/value pairs. The current output appears like this: [{"id":"793","actionname":"test_bsc_interface","actionid":"100"}]. However, I w ...