ncc icon indicating copy to clipboard operation
ncc copied to clipboard

ncc build fails with bun when node isn't installed

Open benjiewheeler opened this issue 1 year ago • 0 comments

When using ncc in a docker build with the oven/bun image, the build fails with the following error:

1.687 error: Module build failed (from ../tmp/@vercel/ncc--bunx/node_modules/@vercel/ncc/dist/ncc/loaders/ts-loader.js):
1.687 Error: Could not load TypeScript compiler with NPM package name `/tmp/@vercel/ncc--bunx/node_modules/@vercel/ncc/dist/ncc/typescript.js`. Are you sure it is correctly installed?
1.687     at loader (/tmp/@vercel/ncc--bunx/node_modules/@vercel/ncc/dist/ncc/loaders/ts-loader.js.cache.js:32:279744)
1.687       at /tmp/@vercel/ncc--bunx/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:38:3792429
1.687       at /tmp/@vercel/ncc--bunx/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:38:792441
1.687       at _done (:9:0)
1.687       at processTicksAndRejections (:55:76)
1.687 
------
Dockerfile:12
--------------------
  10 |     COPY src/ ./src
  11 |     
  12 | >>> RUN bun x @vercel/ncc build ./src/index.ts -o ./dist
  13 |     
  14 |     FROM oven/bun:1.0.6-alpine as run
--------------------
ERROR: failed to solve: process "/bin/sh -c bun x @vercel/ncc build ./src/index.ts -o ./dist" did not complete successfully: exit code: 1

Adding nodejs to the Dockerfile solves this issue:

# build-stage
FROM oven/bun:1.0.6-alpine as build

# vvvvvvvvvvvvvvvvvvvvvvv
# uncommenting this line solves the issue
# RUN apk add --no-cache nodejs
# ^^^^^^^^^^^^^^^^^^^^^^^

WORKDIR /build

# copy package.json & lockfile
COPY package.json bun.lockb ./

# install dependencies
RUN bun install

# add source code
COPY tsconfig.json ./
COPY src/ ./src

# build
RUN bun x @vercel/ncc build ./src/index.ts -o ./dist

# run stage
FROM oven/bun:1.0.6-alpine as run

WORKDIR /app

# copy the files from the build stage
COPY --from=build /build/package.json /build/bun.lockb ./
COPY --from=build /build/dist/ ./dist

# app go brrrrrr
CMD [ "/bin/sh", "-c", "bun run dist/index.js 2>&1" ]

benjiewheeler avatar Oct 27 '23 16:10 benjiewheeler