Error: Cannot find module '/app/backend/index.js'
batoqqqa
FREEOP

a year ago

Hello, I'm trying to host express js app, but I got an Error:

Node.js v18.20.5

node:internal/modules/cjs/loader:1143

throw err;

^

Error: Cannot find module '/app/backend/index.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: []

}

Solved$10 Bounty

Pinned Solution

marktawa
HOBBY

a year ago

Change your start command from "node backend/index.js" to "node index.js"

9 Replies

marktawa
HOBBY

a year ago

Hi

Please show me your project's folder structure (just the top-level files and folders) and your package.json contents here


marktawa

Hi Please show me your project's folder structure (just the top-level files and folders) and your `package.json` contents here

batoqqqa
FREEOP

a year ago

Hello, here it is. I guess i need to toggle the visibility of the project?


marktawa
HOBBY

a year ago

Did you configure your Railway project's root folder to be backend?

By default, Railway runs from the root of the repo, so if your Express app is inside the backend/ folder, you'll need to either set the root directory in Railway to backend, or move the app files to the project root.


marktawa

Did you configure your Railway project's root folder to be `backend`? By default, Railway runs from the root of the repo, so if your Express app is inside the `backend/` folder, you'll need to either set the root directory in Railway to `backend`, or move the app files to the project root.

batoqqqa
FREEOP

a year ago

I am not sure but it seems like yes I configured the project

Attachments


marktawa
HOBBY

a year ago

Show me your build logs. Right from the start


marktawa

Show me your build logs. Right from the start

batoqqqa
FREEOP

a year ago

Here

[Region: asia-southeast1]

May 16 21:10:25

==============

May 16 21:10:25

Using Nixpacks

May 16 21:10:25

==============

May 16 21:10:25

May 16 21:10:25

context: t7nc-ymse

May 16 21:10:25

╔═════════ Nixpacks v1.38.0 ═════════╗

May 16 21:10:25

║ setup │ nodejs_18, npm-9_x ║

May 16 21:10:25

║────────────────────────────────────║

May 16 21:10:25

║ install │ npm i ║

May 16 21:10:25

║────────────────────────────────────║

May 16 21:10:25

║ start │ node backend/index.js ║

May 16 21:10:25

╚════════════════════════════════════╝

May 16 21:10:25

[internal] load build definition from Dockerfile

May 16 21:10:25

[internal] load build definition from Dockerfile 0ms

May 16 21:10:25

[internal] load build definition from Dockerfile

May 16 21:10:25

[internal] load build definition from Dockerfile 12ms

May 16 21:10:25

[internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1745885067

May 16 21:10:26

[internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1745885067 546ms

May 16 21:10:26

[internal] load .dockerignore

May 16 21:10:26

[internal] load .dockerignore 0ms

May 16 21:10:26

[internal] load .dockerignore

May 16 21:10:26

[internal] load .dockerignore 10ms

May 16 21:10:26

[internal] load build context 0ms

May 16 21:10:26

[internal] load build context

May 16 21:10:26

[internal] load build context 41ms

May 16 21:10:26

[stage-0 3/8] COPY .nixpacks/nixpkgs-ffeebf0acf3ae8b29f8c7049cd911b9636efd7e7.nix .nixpacks/nixpkgs-ffeebf0acf3ae8b29f8c7049cd911b9636efd7e7.nix 0ms – CACHED

May 16 21:10:26

[stage-0 4/8] RUN nix-env -if .nixpacks/nixpkgs-ffeebf0acf3ae8b29f8c7049cd911b9636efd7e7.nix && nix-collect-garbage -d 0ms – CACHED

May 16 21:10:26

[stage-0 5/8] COPY . /app/. 0ms – CACHED

May 16 21:10:26

[stage-0 6/8] RUN --mount=type=cache,id=s/84f6c431-6b4b-4ad9-bc6a-a513a3d32c7f-/root/npm,target=/root/.npm npm i 0ms – CACHED

May 16 21:10:26

[stage-0 7/8] RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile 0ms – CACHED

May 16 21:10:26

[stage-0 8/8] COPY . /app 0ms – CACHED

May 16 21:10:26

exporting to docker image format

May 16 21:10:26

exporting to image

May 16 21:10:26

[auth] sharing credentials for asia-southeast1.registry.rlwy.net

May 16 21:10:26

[auth] sharing credentials for asia-southeast1.registry.rlwy.net 0ms

May 16 21:10:28

importing to docker

May 16 21:10:31

importing to docker 3s

May 16 21:10:31

=== Successfully Built! ===

May 16 21:10:31

Run:

May 16 21:10:31

docker run -it asia-southeast1.registry.rlwy.net/84f6c431-6b4b-4ad9-bc6a-a513a3d32c7f:08b13c1b-ad64-40e8-8b06-eac8975cd28e

May 16 21:10:31

Build time: 6.30 seconds


marktawa
HOBBY

a year ago

Show me your Deploy logs


marktawa
HOBBY

a year ago

Change your start command from "node backend/index.js" to "node index.js"


marktawa

Change your start command from "node backend/index.js" to "node index.js"

batoqqqa
FREEOP

a year ago

Thanks, it helped


Status changed to Solved brody about 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...