NodeJS project fails to build

pastor126
HOBBY

a year ago

I'm new here and I'm learning. \The project works perfectly on the local machine, but when going into production the failure occurs. This is the log:

2 warnings found (use --debug to expand):

Jul 07 10:13:31

  • UndefinedVar: Usage of undefined variable '$NIXPACKS_PATH' (line 18)

Jul 07 10:13:31
LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 18)

Jul 07 10:13:31

Jul 07 10:13:31
Dockerfile:20

Jul 07 10:13:31

Jul 07 10:13:31
18 | ENV NIXPACKSPATH /app/nodemodules/.bin:$NIXPACKS_PATH

Jul 07 10:13:31
19 | COPY . /app/.

Jul 07 10:13:31
20 | >>> RUN --mount=type=cache,id=s/ba99d1a2-d06b-448a-bb24-97ee3754c1e3-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-lockfile

Jul 07 10:13:31
21 |

Jul 07 10:13:31
22 | # build phase

Jul 07 10:13:31

Jul 07 10:13:31
ERROR: failed to solve: process "/bin/bash -ol pipefail -c pnpm i --frozen-lockfile" did not complete successfully: exit code: 1

Jul 07 10:13:31

Jul 07 10:13:31
Error: Docker build failed

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

13 Replies

edwardthomson
TRIAL

a year ago

I'm getting this as well, on a project that was building fine on Railway a few days ago.


pastor126
HOBBY

a year ago

And you weren't able to resolve it or have any idea what was happening?



edwardthomson
TRIAL

a year ago

Have just gotten back to this - I'm not sure of the exact cause, but I suspect I had some sort of local caching issue. Deleting node_modules and package.lock and then reinstalling locally and pushing up has resolved my issue. Sorry to not be of more help @pastor126


titusg
PRO

a year ago

Same here on a nodejs application.

Attachments


a year ago

0.287                 This is not the tsc command you are looking for                
0.287                                                                                
0.287
0.287 To get access to the TypeScript compiler, tsc, from the command line either:
0.287
0.287 - Use npm install typescript to first add TypeScript to your project before using npx
0.287 - Use yarn to avoid accidentally running code from un-installed packages

titusg
PRO

a year ago

So, to troubleshoot this, I created my own Dockerfile. Everything works as expected. I am able to build the image and run it. But when I pushed it on Railway, I'm still getting the same error "This is not the tsc command you are looking for". Any clue ?

# See all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:alpine AS base
WORKDIR /usr/src/app



# Install dependencies into temp directory
# This will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# Install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# Copy node_modules from temp directory
# Then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules ./node_modules
COPY . .

# [optional] tests & build
ENV NODE_ENV=production

RUN bun test
RUN bun run build

# Copy production dependencies and source code into final image
# Use Node.js optimized image for the final stage
FROM node:20-alpine AS release
WORKDIR /usr/src/app

# Copy production dependencies and source code into final image
COPY --from=install /temp/prod/node_modules ./node_modules
COPY --from=prerelease /usr/src/app/dist ./dist
COPY --from=prerelease /usr/src/app/package.json .

# Run the app
USER node
EXPOSE 8080/tcp
ENTRYPOINT [ "node", "dist/index.js" ]

titusg
PRO

a year ago

It always fails here, with NIXPACK or with a custom Dockerfile.

RUN bun run build

The only thing build is doing is:

tsc -p tsconfig.json && tsc-alias -p tsconfig.json


titusg
PRO

a year ago

I'm attaching two log files.

It's the same version of the service.

The only thing I did was "Redeploy"

  • Log #1 - Fails with the typescript error

  • Log #2 - Success


a year ago

The error message includes the solution, please read the error message.


titusg
PRO

a year ago

How do you explain that it worked without me changing anything, just rebuilding the app ?


a year ago

Please read the error message.


pastor126
HOBBY

a year ago

I managed to solve it by creating a 'nixpacks.toml' file at the root with the code: providers = ["node"]

[phases.install]

cmds = ["npm install -g corepack", "corepack enable", "corepack prepare pnpm@9.1.0 --activate", "pnpm install"]