Problem with NestJS deployment in mono-repo

Hi everybody :wave:

I am trying to deploy my NestJS project. Everything is fine until ‘npm run start:prod’ where I get the following error.

My code is based in a monorepo and the folder is /backend .
I have added that as a rootDir,

Can you help me figuring out what is wrong?

Apr 19 04:58:13 PM  ==> Starting service with 'npm run start:prod'
Apr 19 04:58:15 PM  
Apr 19 04:58:15 PM  > insurance_backend@0.0.1 start:prod /opt/render/project/src/backend
Apr 19 04:58:15 PM  > node dist/main
Apr 19 04:58:15 PM  
Apr 19 04:58:15 PM  internal/modules/cjs/loader.js:888
Apr 19 04:58:15 PM    throw err;
Apr 19 04:58:15 PM    ^
Apr 19 04:58:15 PM  
Apr 19 04:58:15 PM  Error: Cannot find module '/opt/render/project/src/backend/dist/main'
Apr 19 04:58:15 PM      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
Apr 19 04:58:15 PM      at Function.Module._load (internal/modules/cjs/loader.js:730:27)
Apr 19 04:58:15 PM      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Apr 19 04:58:15 PM      at internal/main/run_main_module.js:17:47 {
Apr 19 04:58:15 PM    code: 'MODULE_NOT_FOUND',
Apr 19 04:58:15 PM    requireStack: []
Apr 19 04:58:15 PM  }
Apr 19 04:58:15 PM  npm ERR! code ELIFECYCLE
Apr 19 04:58:15 PM  npm ERR! errno 1
Apr 19 04:58:15 PM  npm ERR! insurance_backend@0.0.1 start:prod: `node dist/main`
Apr 19 04:58:15 PM  npm ERR! Exit status 1
Apr 19 04:58:15 PM  npm ERR!
Apr 19 04:58:15 PM  npm ERR! Failed at the insurance_backend@0.0.1 start:prod script.
Apr 19 04:58:15 PM  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Hey there,
So MODULE_NOT_FOUND errors typically don’t lie and an error like this would suggest that the build might not be outputting to the path that your start script is expecting to find.

You mention you’re using a monorepo, are you setting the rootDirectory of your service to the folder in your repo that your backend is in, that will keep everything relative to that directory and might help here,

Regards,

John B

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