Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remix CLI required for remix build, but only available in @remix-run/dev #9775

Closed
Hansenq opened this issue Jul 18, 2024 · 1 comment
Closed

Comments

@Hansenq
Copy link

Hansenq commented Jul 18, 2024

Reproduction

Remix recommends placing @remix-run/dev in devDependencies, so it's not bundled in the server.

When building Remix in a Dockerfile, we normally prune out development dependencies before building the app. When using Turborepo in a monorepo, this is accomplished by the turbo prune command.

However, once the app is pruned, we lose access to devDependencies. As a result, the remix CLI is no longer available, and we can't run remix vite:build. The current temporary solution is to put @remix-run/dev into production dependencies, but that's not recommended by the Remix team.

Note that this doesn't only happen with Docker; it's just much more evident with Docker because we prune the repo before building. This bug will occur with any build process that removes devDependencies before running remix vite:build.

Dockerfile:

# base node image
FROM node:bullseye-slim as base

RUN apt-get update && apt-get install -y openssl

# == Pruner
# Throwaway stage to reduce size of final image
FROM base as builder
RUN mkdir /app
WORKDIR /app
RUN npm install -g turbo
COPY . .
RUN turbo prune --docker

# == Installer/Builder
# Throwaway stage to reduce size of final image
FROM base as installer
RUN mkdir /app
WORKDIR /app
RUN npm install -g turbo
# Copy package.json over, install dependencies
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/package-lock.json ./package-lock.json
RUN npm clean-install
# Build the project
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
# This step here fails if the remix CLI is not present.
RUN npx turbo run build 

# == Runner
FROM base as runner
WORKDIR /app
ENV NODE_ENV=production
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 remix
USER remix

COPY --from=installer --chown=remix:nodejs /app/ ./

WORKDIR /app

CMD ["npm", "run", "start"]

This issue was reported in #1233, but was closed without fixing it.

I think this can be fixed if we included the remix CLI in one of the other packages, like @remix-run/node or @remix-run/serve.

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M2 Pro
    Memory: 163.08 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.1.0 - ~/.nvm/versions/node/v21.1.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v21.1.0/bin/npm
    bun: 1.1.7 - ~/.bun/bin/bun
  Browsers:
    Chrome: 126.0.6478.128
    Safari: 17.5

Used Package Manager

npm

Expected Behavior

The build should succeed.

Actual Behavior

Running npm run build which runs remix vite:build fails with the following error: sh: 1: remix: not found

> [installer 11/11] RUN npm run build
> 2.081 • Packages in scope: app
> 2.105 • Running build in 1 packages
> 2.117 • Remote caching disabled
> 2.266 app:build: cache bypass, force executing aa4ba35cdfb9ad79
> 2.734 app:build:
> 2.745 app:build: > app@1.0.0 build
> 2.745 app:build: > remix vite:build
> 2.745 app:build:
> 2.752 app:build: sh: 1: remix: not found
> 2.788 app:build: npm error Lifecycle script `build` failed with error:
> 2.795 app:build: npm error code 127
> 2.795 app:build: npm error path /app/apps/app
> 2.810 app:build: npm error workspace app@1.0.0
> 2.810 app:build: npm error location /app/apps/app
> 2.812 app:build: npm error command failed
> 2.812 app:build: npm error command sh -c remix vite:build
> 2.867 app:build: ERROR: command finished with error: command (/app/apps/app) /usr/local/bin/npm run build exited (127)
> 2.867 app#build: command (/app/apps/app) /usr/local/bin/npm run build exited (127)
> 2.873
> 2.873 Tasks: 0 successful, 1 total
> 2.873 Cached: 0 cached, 1 total
> 2.873 Time: 969ms
> 2.873 Failed: app#build
> 2.873
> 2.886 ERROR run failed: command exited (127)

@Hansenq
Copy link
Author

Hansenq commented Jul 19, 2024

Ok, turns out this wasn't remix's fault. The command is missing due to an upstream node 22.5.0 issue where npm install and npm clean-install were silently failing. Sorry!

@Hansenq Hansenq closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant