Cannot find module '/usr/src/app/app.js'

hongdevsTRIAL

6 months ago

You reached the start of the range  Oct 28, 2024 11:32 PM

Starting Container

container event container restart

node:internal/modules/cjs/loader:936

  throw err;

  ^



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

    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)

    at Function.Module._load (node:internal/modules/cjs/loader:778:27)

    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

    at node:internal/main/run_main_module:17:47 {

  code: 'MODULE_NOT_FOUND',

  requireStack: []

}



Node.js v17.7.1

node:internal/modules/cjs/loader:936

  throw err;

  ^

This is my Dockerfile:

FROM node:17.7.1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .
RUN npm install
RUN npm install -g nodemon
EXPOSE 3000
CMD ["nodemon", "app.js"]

This is my package.json:

{
  "name": "todolist-v1",
  "version": "1.0.0",
  "description": "",
  "main": "src/app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "engines": {
    "node": "17.7.1"
  },
  "dependencies": {
    "alert": "^6.0.1",
    "body-parser": "^1.19.1",
    "connect-mongo": "^5.1.0",
    "dotenv": "^16.0.0",
    "ejs": "^3.1.6",
    "express": "^4.17.2",
    "express-session": "^1.17.3",
    "lodash": "^4.17.21",
    "mongoose": "^6.2.9",
    "nodemon": "^3.0.2",
    "passport": "^0.6.0",
    "passport-local": "^1.0.0",
    "passport-local-mongoose": "^7.1.2"
  }
}

I can also verify that app.js is under the /src directory.

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

1 Replies

6 months ago

  1. Please never use nodemon in production, you need to run the .js file with node directly.

  2. Delete the Procfile.