cannot deploy nestjs app
justmexmehak
HOBBYOP

10 months ago

The build is successful as the build logs say Successfully built but it fails during deployment with the following error:

node:internal/modules/cjs/loader:1143

throw err;

^

Error: Cannot find module '/app/dist/main.js'

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

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

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

at node:internal/main/run_main_module:28:49 {

code: 'MODULE_NOT_FOUND',

requireStack: []

}

Node.js v18.20.5

$10 Bounty

7 Replies

Railway
BOT

10 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


fra
HOBBY

10 months ago

how do you deploy? it seems like you didn't build the app


justmexmehak
HOBBYOP

10 months ago

im deploying via github and i have the following command in my Procfile web: npm run build && npm run start:prod


fra
HOBBY

10 months ago

can you try copying npm run start:prod in Setting => Deploy => Custom start command?


justmexmehak
HOBBYOP

10 months ago

still didnt work here is my github repo https://github.com/justmexmehak/emr-backend


fra
HOBBY

10 months ago

can you check the root directory in Settings => Source => Root Directory? if you see /app replace it with /.

Also I can see that start:prod has also npm run build so what I would suggest is for now to create a new script:

"start:railway":"node dist/main.js"

and try with this script.

If it doesn't work then I can't help you and you will need to wait for someone else 🙂


samimwebdev
PRO

10 months ago

Have you tried to build the project locally ? Running the production build locally triggers the same error?

it seems after deploying for production /dist.main.js file doesn't exists

Modify your nest-cli.json (Add output path)

{

"$schema": "https://json.schemastore.org/nest-cli",

"collection": "@nestjs/schematics",

"sourceRoot": "src",

"compilerOptions": {

"deleteOutDir": true,

"outputPath": "./dist"

}

}

then place npm run start:prod in Setting => Deploy => Custom start command on Railway Service setting


Welcome!

Sign in to your Railway account to join the conversation.

Loading...