spiderangel
spiderangel

Reputation: 43

heroku Error: Cannot find module '/app/index.js'

I am hosting a university project on heroku and i need to host a django app which also needs an npm library but i searched alot on how to do this and eventualy i thought i got the hand of it but now i am getting this error:

2018-06-14T10:19:22.798022+00:00 app[web.1]:     throw err;

2018-06-14T10:19:22.798023+00:00 app[web.1]:     ^

2018-06-14T10:19:22.798024+00:00 app[web.1]: 

2018-06-14T10:19:22.798026+00:00 app[web.1]: Error: Cannot find module '/app/server.js'

2018-06-14T10:19:22.798028+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:547:15)

2018-06-14T10:19:22.798029+00:00 app[web.1]:     at Function.Module._load (module.js:474:25)

2018-06-14T10:19:22.798030+00:00 app[web.1]:     at Function.Module.runMain (module.js:693:10)

2018-06-14T10:19:22.798031+00:00 app[web.1]:     at startup (bootstrap_node.js:191:16)

2018-06-14T10:19:22.798033+00:00 app[web.1]:     at bootstrap_node.js:612:3

this is my package.json:

{
  "name": "dpl-webtech",
  "version": "1.0.0",
  "description": "DBL - Webtech Group D24",
  "main": "index.js",
  "scripts": {
    "start": "nf start"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/spiderangel123/DPL-WebTech.git"
  },
  "author": "Ahmad Alsarakbi",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/spiderangel123/DPL-WebTech/issues"
  },
  "homepage": "https://github.com/spiderangel123/DPL-WebTech#readme",
  "engines": {
    "node": "8.11.2",
    "npm": "6.1.0"
  },
  "dependencies": {
    "npm": "^6.1.0",
    "phantomjs-prebuilt": "^2.1.16"
  }
}[![enter image description here][1]][1]

and here is my procfile:

web: gunicorn DBL.wsgi
web: node ./index.js

files structureg

Upvotes: 2

Views: 8866

Answers (4)

Sérgio Junior
Sérgio Junior

Reputation: 309

I was getting this error, in my case, it was because my server starter file was index.ts and not index.js as I'm using typescript.

Upvotes: 0

John Doe
John Doe

Reputation: 1172

I had the same issue recently, although the build was successful.

The problem does not come from your project repositories structure where an app folder would be missing. Heroku apps include a Procfile that specifies the commands that are executed by the app’s dynos. When you load your app, Heroku will start a web process type.

My guess is you don't have a Procfile, and you don't have a web process defined.

The easiest way to do is to add a Procfile at the root of your project. The Procfile has no extension to its name. Inside of it, you add a web process with the following structure : <process type>: <command>

For a NodeJS app, you can typically have the following instruction :

web: node dist/server/index.js

You only need to customize it to your app.

Upvotes: 3

spiderangel
spiderangel

Reputation: 43

You don't need to include web: node index.js if you just need to include packages but it was mentioned to add it to Procfile everywhere i read about how to use npm with heroku so i had the misconception that it wont work unless i add it.

Upvotes: -1

Ashu_Sharma
Ashu_Sharma

Reputation: 21

Can you please share the file structure.

This error occurs when the file path to the server.js is not correct, So check once if the file path that heroku is taking is correct or not.

Upvotes: 2

Related Questions