npm run sync:uploadsnot executing for Node.js backend
a month ago
Dear Railway Support Team,
I am experiencing a persistent issue with the deployment of my Node.js backend application on Railway.
Repository Link: https://github.com/KubriakZahoor107/Art-Beckend/
Railway Username: kubriakzahoor107
Contact Email: konstantin.kubriak@gmail.com
Application URL: https://web-production-2730f.up.railway.app
**Problem Description:**
Our application requires copying local 'uploads' files from `server/uploads` to `[repo_root]/.nixpacks/files/uploads` during the build phase. We utilize a custom script, `server/scripts/sync-uploads.mjs`, which is invoked via `nixpacks.toml`. However, despite correct configuration of `nixpacks.toml` at the repository root, the `sync-uploads.mjs` script does not appear to execute, and its expected output is absent from the build logs. Consequently, the target directory (`/app/.nixpacks/files/uploads`) remains empty in the running container, leading to 404 errors when attempting to access uploaded files (e.g., `https://web-production-2730f.up.railway.app/uploads/1733248835049-824543928.jpg`).
**Configuration Details:**
1. **Repository Structure (relevant parts):**
```
Art-Beckend/
├── nixpacks.toml (located at the repository root)
└── server/
├── package.json (defines "build" and "sync:uploads" scripts)
├── uploads/ (source directory for files to be copied)
└── scripts/
└── sync-uploads.mjs (the custom copying script)
```
2. **`nixpacks.toml` content (at repository root):**
```toml
[phases.install]
cmds = [
"npm ci --prefix server"
]
[phases.build]
cmds = [
"npm run build --prefix server",
"npm run sync:uploads --prefix server" # This command appears not to be executed
]
[start]
cmd = "npm run start:prod --prefix server"
```
3. **Relevant scripts in `server/package.json`:**
```json
{
"name": "server",
"scripts": {
"build": "tsc -p tsconfig.json", // This TypeScript build also seems to be skipped
"sync:uploads": "node scripts/sync-uploads.mjs",
"start:prod": "prisma migrate deploy && node dist/index.js"
}
}
```
**Observed Behavior in Railway Deployment Logs (Example Snippet):**
Starting Container npm warn config production Use --omit=dev instead.
server@1.0.0 start:prod prisma migrate deploy && node dist/index.js
Prisma schema loaded from prisma/schema.prisma Datasource "db": PostgreSQL database "railway", schema "public" at "postgres.railway.internal:5432"
3 migrations found in prisma/migrations No pending migrations to apply. info:
Serving uploads from /app/.nixpacks/files/uploads warn:
Кандидат uploads відсутній: /.nixpacks/files/uploads (source=.nixpacks/files/uploads (local repo)) // ... (other warnings about missing upload candidates) ... info:
Successfully connected to the database info:
API listening on https://0.0.0.0:8080 (NODE_ENV=production) // ... (access logs) ... warn:
Upload not found: /app/.nixpacks/files/uploads/1733248835049-824543928.jpg
**Crucially, there is no output in the logs indicating the execution of `npm run build --prefix server` or `npm run sync:uploads --prefix server` during any build phase. The logs directly transition from "Starting Container" to the application's `start:prod` command output.**
**Steps Taken So Far:**
1. Ensured `nixpacks.toml` is correctly placed at the repository root.
2. Removed all comments from `nixpacks.toml`.
3. Updated `server/scripts/sync-uploads.mjs` to include extensive logging (which is not visible in logs).
4. Committed and pushed all changes to the GitHub repository.
5. Attempted forced redeployment/rebuilds with cache clearing via the Railway dashboard multiple times.
6. Verified local Git status is clean and reflects only intended changes.
**Our Hypothesis:**
It appears that Nixpacks on Railway is either not recognizing or not executing the commands defined within the `[phases.build]` section of our `nixpacks.toml`. We expect these commands (including `npm run build` for TypeScript compilation and `npm run sync:uploads`) to run prior to the application's startup.
Could you please investigate why the `build` phase, as specified in our `nixpacks.toml`, is being skipped or not fully processed by Nixpacks during deployment? Any insights or guidance on resolving this would be greatly appreciated.
Thank you for your time and assistance.
Sincerely,
Konstantin Kubriak4 Replies
a month 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!
a month ago
Crucially, there is no output in the logs indicating the execution of `npm run build --prefix server` or `npm run sync:uploads --prefix server` during any build phase. The logs directly transition from "Starting Container" to the application's `start:prod` command output.
The build commands you specified wouldn't show up in the Deploy Logs for your deployment, it'll show up in the Build Logs instead, could you share your build logs here? Most important the top part, you should see a box up there. Or just download it all via the download icon in the top right of the logs container
a month ago
Hello Railway Team,
Thank you for guiding me to the Build Logs. I've analyzed them and it appears that Nixpacks is **not using my `nixpacks.toml` configuration at all**.
The generated Railpack plan in the build logs is as follows:
Steps
──────────
▸ install
$ npm ci
▸ build
$ npm run build
Deploy
──────────
$ npm run start:prod
This plan uses default `npm ci`, `npm run build`, and `npm run start:prod` commands, **without the `--prefix server` arguments** and, most importantly, **completely omits my `npm run sync:uploads --prefix server` command** which is defined in the `[phases.build]` section of my `nixpacks.toml`.
My `nixpacks.toml` is located at the repository root and contains:
Ini, TOML
[phases.install]
cmds = [
"npm ci --prefix server"
]
[phases.build]
cmds = [
"npm run build --prefix server",
"npm run sync:uploads --prefix server"
]
[start]
cmd = "npm run start:prod --prefix server"
It seems Nixpacks is falling back to an auto-detected plan instead of using my custom `nixpacks.toml`. Could you please investigate why `nixpacks.toml` is not being honored in this deployment?
Thank you for your continued assistance.
Best regards,
Konstantin Kubriaka month ago
Hey there!
Railway now uses Railpack by default, If you'd like to look at migrating to Railpack, you can get started at the docs https://railpack.com/getting-started.
f you truly want it to read your nixpacks.tomlmake sure to select it on Service -> Settings -> Build.
I put this repo up with a setup close to yours and was able to get it deployed. Maybe you can take a look to compare?
https://github.com/crisog/railway-deploy/tree/nix
Status changed to Solved chandrika • about 1 month ago