Error: Cannot find module

Hello community, I have a problem with my first deployment of the express application in, the console shows an error Error: The module ‘dotenv’ is not found, it works locally, when I execute the start command it works, what could be happening? I hope you can help me, thanks !

Nov 2 03:09:17 PM  internal/modules/cjs/loader.js:888
Nov 2 03:09:17 PM    throw err;
Nov 2 03:09:17 PM    ^
Nov 2 03:09:17 PM  
Nov 2 03:09:17 PM  Error: Cannot find module 'dotenv'
Nov 2 03:09:17 PM  Require stack:
Nov 2 03:09:17 PM  - /opt/render/project/src/dist/index.js
Nov 2 03:09:17 PM      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
Nov 2 03:09:17 PM      at Function.Module._load (internal/modules/cjs/loader.js:730:27)
Nov 2 03:09:17 PM      at Module.require (internal/modules/cjs/loader.js:957:19)
Nov 2 03:09:17 PM      at require (internal/modules/cjs/helpers.js:88:18)
Nov 2 03:09:17 PM      at Object.<anonymous> (/opt/render/project/src/dist/index.js:6:1)
Nov 2 03:09:17 PM      at Module._compile (internal/modules/cjs/loader.js:1068:30)
Nov 2 03:09:17 PM      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
Nov 2 03:09:17 PM      at Module.load (internal/modules/cjs/loader.js:933:32)
Nov 2 03:09:17 PM      at Function.Module._load (internal/modules/cjs/loader.js:774:14)
Nov 2 03:09:17 PM      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
Nov 2 03:09:17 PM    code: 'MODULE_NOT_FOUND',
Nov 2 03:09:17 PM    requireStack: [ '/opt/render/project/src/dist/index.js' ]
Nov 2 03:09:17 PM  }

Hi there,

Thanks for reaching out.

It sounds like you’re not installing dependencies. Could you share some of you service settings, e.g. build & start commands, root directory, etc. A common set of commands would be:

  • Build Command: npm install; npm run build
  • Start Command: npm run start

However, these are just example, your own app may require different commands (e.g. maybe you use yarn, etc.)


Hi @al_ps thanks for replying !
My build command: npm run build
My start command: npm run start

As you can see in the console output, after running npm run build and npm run start, it works locally and there is no error


My folders

My index.ts file, where dotenv is required !

My database configuration file, where dotenv is required, I no longer need dotenv in any other file.

From your Build Commands, you’re not installing your dependencies. Your Build Command needs to be npm install; npm run build.

Environments will be different, your Node packages were likely installed locally a long time ago, you need to run the commands to get your app up and running from scratch when deploying to a new environment.


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