Internal/modules/cjs/loader.js:888 Error: Cannot find module 'express'

I;am having trouble with deploy my MERN app, all good to run backend.

backend@1.0.0 start /opt/render/project/src/backend
Mar 30 11:48:47 PM > node index.js
Mar 30 11:48:47 PM
Mar 30 11:48:48 PM internal/modules/cjs/loader.js:888
Mar 30 11:48:48 PM throw err;
Mar 30 11:48:48 PM ^
Mar 30 11:48:48 PM
Mar 30 11:48:48 PM Error: Cannot find module ‘express’
Mar 30 11:48:48 PM Require stack:
Mar 30 11:48:48 PM - /opt/render/project/src/backend/index.js
Mar 30 11:48:48 PM at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
Mar 30 11:48:48 PM at Function.Module._load (internal/modules/cjs/loader.js:730:27)
Mar 30 11:48:48 PM at Module.require (internal/modules/cjs/loader.js:957:19)
Mar 30 11:48:48 PM at require (internal/modules/cjs/helpers.js:88:18)
Mar 30 11:48:48 PM at Object. (/opt/render/project/src/backend/index.js:1:17)
Mar 30 11:48:48 PM at Module._compile (internal/modules/cjs/loader.js:1068:30)
Mar 30 11:48:48 PM at Object.Module._extensions…js (internal/modules/cjs/loader.js:1097:10)
Mar 30 11:48:48 PM at Module.load (internal/modules/cjs/loader.js:933:32)
Mar 30 11:48:48 PM at Function.Module._load (internal/modules/cjs/loader.js:774:14)
Mar 30 11:48:48 PM at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
Mar 30 11:48:48 PM code: ‘MODULE_NOT_FOUND’,
Mar 30 11:48:48 PM requireStack: [ ‘/opt/render/project/src/backend/index.js’ ]
Mar 30 11:48:48 PM }
Mar 30 11:48:48 PM npm ERR! code ELIFECYCLE
Mar 30 11:48:48 PM npm ERR! errno 1
Mar 30 11:48:48 PM npm ERR! backend@1.0.0 start: node index.js
Mar 30 11:48:48 PM npm ERR! Exit status 1
Mar 30 11:48:48 PM npm ERR!
Mar 30 11:48:48 PM npm ERR! Failed at the backend@1.0.0 start script.
Mar 30 11:48:48 PM npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Mar 30 11:48:48 PM
Mar 30 11:48:48 PM npm ERR! A complete log of this run can be found in:
Mar 30 11:48:48 PM npm ERR! /opt/render/.cache/_logs/2023-03-30T21_48_48_148Z-debug.log

My package.json
{
“name”: “backend”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“start”: “node index.js”,
“test”: “echo "Error: no test specified" && exit 1”
},
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“bcrypt”: “^5.1.0”,
“body-parser”: “^1.20.1”,
“cloudinary”: “^1.34.0”,
“cors”: “^2.8.5”,
“dotenv”: “^16.0.3”,
“express”: “^4.18.2”,
“express-async-handler”: “^1.2.0”,
“jsonwebtoken”: “^9.0.0”,
“mongoose”: “^6.9.0”,
“morgan”: “^1.10.0”,
“multer”: “^1.4.5-lts.1”,
“nodemailer”: “^6.9.1”,
“sharp”: “^0.31.3”,
“slugify”: “^1.6.5”,
“uniqid”: “^5.4.0”
},
“devDependencies”: {}
}

Put npm ci in place of build command if you are using npm. I was initially using npm i but on automated services, I read that npm ci is used. Worked for me.

Tanks for answer but it doesn’t work. My build command is running properly. My start comment cannot find module ‘express’, thats the problem.

Hi,

If you’re getting Cannot find module ‘express’

It sounds like you’re not installing your dependencies. npm install (or yarn, whichever manager you use locally) as your Build Command should install your dependencies.

MERN apps are often monorepos so maybe you have multiple folders with multiple package.json files. You’ve clearly defined the error, so you’ll need to ensure you’re installing the packages you’re calling in the Start Command.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.