Bug in Remix template: using node v12 breaks builds

 => ERROR [build 5/6] RUN bun run build                                                                      0.3s
------
 > [build 5/6] RUN bun run build:
0.166 $ remix build
0.231 /app/node_modules/@remix-run/dev/dist/cli/run.js:158
0.231   flags.interactive = flags.interactive ?? require.main === module;
0.231                                          ^
0.231
0.231 SyntaxError: Unexpected token '?'
0.231     at wrapSafe (internal/modules/cjs/loader.js:915:16)
0.231     at Module._compile (internal/modules/cjs/loader.js:963:27)
0.231     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0.231     at Module.load (internal/modules/cjs/loader.js:863:32)
0.231     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0.231     at Module.require (internal/modules/cjs/loader.js:887:19)
0.231     at require (internal/modules/cjs/helpers.js:74:18)
0.231     at Object.<anonymous> (/app/node_modules/@remix-run/dev/dist/cli/index.js:15:11)
0.231     at Module._compile (internal/modules/cjs/loader.js:999:30)
0.231     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0.234 error: script "build" exited with code 1 (SIGHUP)
#10 [build 2/7] RUN node --version
#10 0.208 v12.22.12
#10 DONE 0.2s

Need node v14+, the Dockerfile fly creates uses node v12. The dockerfile needs to be modified to install a modern node version:

...
# Install node modules
COPY --link bun.lockb package-lock.json package.json ./
RUN bun install

# Update nodejs version
ARG NODE_MAJOR=21
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install nodejs -y

# Copy application code
COPY --link . .
...

Also get

2023-12-29T14:13:11Z app[568330ddf52d78] iad [info]SyntaxError: Export named 'renderToPipeableStream' not found in module '/app/node_modules/react-dom/server.browser.js'.

Which is not present when building and running on mac, but within the docker container.

Again it’s an issue with running using node, not bun. I modified the dockerfile to install node again and it works fine

Tracking a related issue in bun github, as it seems that it should be running with bun: Remix running with node, not bun · Issue #7918 · oven-sh/bun · GitHub

Related Add Bun pt. 2 · remix-run/remix · Discussion #7413 · GitHub

To get it working, the final dockerfile looks like:

# syntax = docker/dockerfile:1

# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.0.15
FROM oven/bun:${BUN_VERSION}-slim as base

LABEL fly_launch_runtime="Remix"

# Remix app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link bun.lockb package-lock.json package.json ./
RUN bun install

# Update nodejs version
ARG NODE_MAJOR=21
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install nodejs -y

# Copy application code
COPY --link . .

# Build application
RUN bun run build

# Remove development dependencies
RUN rm -rf node_modules && \
    bun install --ci


# Final stage for app image
FROM base

# Update nodejs version
ARG NODE_MAJOR=21
RUN apt update
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
RUN apt-get install nodejs -y

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "run", "start" ]

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.