Question

PM2 Start Appname Returning Error Cannot Find Modules in Ubuntu 18.04 LTS

Posted April 9, 2020 2.5k views
Node.jsUbuntu 18.04

This is my first nodejs app and when I try to run the app using PM2 then app start and immediately it’s become to errored and pm2 logs showing this

/root/.pm2/logs/app-out.log last 15 lines:
/root/.pm2/logs/app-error.log last 15 lines:
1|app      |     at Module.load (module.js:565:32)
1|app      |     at tryModuleLoad (module.js:505:12)
1|app      |     at Function.Module._load (module.js:497:3)
1|app      |     at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkLegacy.js:28:21) code: 'MODULE_NOT_FOUND' }
1|app      | { Error: Cannot find module 'express'
1|app      |     at Function.Module._resolveFilename (module.js:547:15)
1|app      |     at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
1|app      |     at require (internal/module.js:11:18)
1|app      |     at Object.<anonymous> (/var/www/whatsclone/app.js:18:17)
1|app      |     at Module._compile (module.js:652:30)
1|app      |     at Object.Module._extensions..js (module.js:663:10)
1|app      |     at Module.load (module.js:565:32)
1|app      |     at tryModuleLoad (module.js:505:12)
1|app      |     at Function.Module._load (module.js:497:3)
1|app      |     at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkLegacy.js:28:21) code: 'MODULE_NOT_FOUND' }

I have tried sudo pm2 update | npm install | npm install express

Nothing fixed for me. Please help me

node -v
v8.10.0

npm -v
3.5.2

Thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Are you running these commands in your project folder? It might be that these are not installed globally.
Run this in your project folder:

npm install express --save

And also make sure you run your app from the project folder.
Let me know if this works or got any more questions.

  • Hi,

    I have tested the same

    Output come like this

    /root/.pm2/logs/Your-app-name-out.log last 15 lines:
    /root/.pm2/logs/Your-app-name-error.log last 15 lines:
    0|Your app |     at Module.load (module.js:565:32)
    0|Your app |     at tryModuleLoad (module.js:505:12)
    0|Your app |     at Function.Module._load (module.js:497:3)
    0|Your app |     at Module.require (module.js:596:17) code: 'MODULE_NOT_FOUND' }
    0|Your app | { Error: Cannot find module 'express'
    0|Your app |     at Function.Module._resolveFilename (module.js:547:15)
    0|Your app |     at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
    0|Your app |     at require (internal/module.js:11:18)
    0|Your app |     at Object.<anonymous> (/var/www/whatsclone/app.js:18:17)
    0|Your app |     at Module._compile (module.js:652:30)
    0|Your app |     at Object.Module._extensions..js (module.js:663:10)
    0|Your app |     at Module.load (module.js:565:32)
    0|Your app |     at tryModuleLoad (module.js:505:12)
    0|Your app |     at Function.Module._load (module.js:497:3)
    0|Your app |     at Module.require (module.js:596:17) code: 'MODULE_NOT_FOUND' }
    

    package.json is here

    {
      "name": "whatsclone",
      "version": "1.0.0",
      "description": "restfull whatscloneAPI",
      "private": true,
      "scripts": {
        "start": "node ./bin/www",
        "test": "grunt test"
      },
      "main": "./bin/www",
      "keywords": [
        "whatsclone",
        "api",
        "chat",
        "call"
      ],
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "grunt": "^1.0.4",
        "grunt-apidoc": "^0.11.0",
        "grunt-contrib-watch": "^1.1.0",
        "grunt-mocha-test": "^0.13.3",
        "grunt-nodemon": "^0.4.2",
        "mocha": "^6.2.2",
        "nodemon": "^2.0.1"
      },
      "dependencies": {
        "async": "^3.1.0",
        "basic-auth": "^2.0.1",
        "body-parser": "^1.19.0",
        "composable-middleware": "^0.3.0",
        "connect-mongo": "^3.2.0",
        "cookie-parser": "^1.4.4",
        "dotenv": "^8.2.0",
        "ejs": "^2.6.2",
        "express": "^4.17.1",
        "express-jwt": "^5.3.1",
        "express-session": "^1.17.0",
        "express-validator": "^5.3.1",
        "i18n": "^0.8.4",
        "jsonwebtoken": "^8.5.1",
        "lusca": "^1.6.1",
        "mongodb": "^3.3.5",
        "mongoose": "^5.7.13",
        "morgan": "^1.9.1",
        "mosca": "^2.8.3",
        "mqtt": "^3.0.0",
        "multer": "^1.4.2",
        "readdir": "0.1.0",
        "serve-favicon": "^2.5.0",
        "twilio": "^3.37.1",
        "underscore": "^1.9.1",
        "uuid": "^3.3.3"
      }
    }
    
Submit an Answer