Error: Cannot find module 'express'

crinklepackageHOBBY

3 months ago

I'm getting this deploy crash. Any idea about what might be happening?

Error: Cannot find module 'express' Require stack: - /app/dist/index.js ... (rest of stack trace)

Here's a summary of the problem and the troubleshooting steps I've already taken:

  • Intermittent Nature: The error does not occur consistently. Sometimes the deployment succeeds, and sometimes it fails with this "Cannot find module 'express'" error.

  • Local Docker Build: My local Docker builds are successful. The application runs correctly when built and run locally using Docker. This indicates that the express dependency is correctly listed in my package.json and installed during the Docker build process.

  • Dockerfile: I am using a multi-stage Docker build. I install all dependencies in the build stage and then copy the node_modules folder, package.json, and yarn.lock to the runtime stage. I then install only production dependencies in the runtime stage using yarn install --production.

  • Dependency Management: I am using Yarn 4 for dependency management.

  • Troubleshooting Steps:

    • I have tried clearing the build cache on Railway by making small, insignificant changes to my code and redeploying. This sometimes works, but the issue recurs.

    • I have verified that express is listed as a dependency in my package.json file.

    • I have tried regenerating my yarn.lock file locally and committing the changes.

    • I have tried rebuilding the Docker image locally multiple times.

    • I have tried different variations of my Dockerfile (including installing dependencies in the runtime stage). However, these changes have either broken my local build or not resolved the issue on Railway.

Closed

2 Replies

crinklepackageHOBBY

3 months ago

Dockerfile attached.

Attachments


3 months ago

Hello,

Please do not open duplicate threads.


Status changed to Awaiting User Response railway[bot] 3 months ago


Status changed to Closed brody 3 months ago