Backend Deployment Issue - "Error: Cannot find module '/app/dist/main.js'"
iadeanalytic
HOBBYOP

10 months ago

I am encountering a persistent issue with deploying my NestJS backend application on your platform. The build process completes successfully without any apparent errors, but when the container starts, it fails with the error: "Error: Cannot find module '/app/dist/main.js'".

My tsconfig.json is configured to output the compiled JavaScript files to the ./dist directory. The build logs indicate that the build process (using npm run build) finishes successfully. However, when I try to start the application using node dist/main.js (or npm run start:prod which executes the same), the module is not found.

I have also tried to inspect the contents of the /app/dist directory at startup by injecting code into my main.ts to list the directory's contents. The logs from this attempt show the error: "Error: ENOENT: no such file or directory, scandir '/app/dist'", indicating that the /app/dist folder does not exist in the container at runtime.

Here are the relevant logs:

Build Logs:

[Include the successful build logs you shared previously]

"Starting Container" Logs (showing the MODULE_NOT_FOUND and ENOENT errors):

[Include the logs showing "Error: Cannot find module '/app/dist/main.js'" and the "Error: ENOENT: no such file or directory, scandir '/app/dist'"]

My "Start Command" in Railway is currently set to node dist/main.js. I have also tried npm run start:prod.

It seems that the dist folder, which should be created during the build, is not present in the container when the application starts. Could you please advise on what might be causing this issue and what steps I need to take to ensure that the built files are available in the container at runtime?

Any insights or guidance you can provide would be greatly appreciated.

Thank you for your time and assistance.

Sincerely,

Solved

1 Replies

It looks like you have a different error, that you are trying to connect your database? Are you passing in the correct value?


Status changed to Awaiting User Response Railway 10 months ago


Railway
BOT

7 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway 7 months ago


Loading...