Error when running `yarn rw build api` command in a Dockerfile

The error I see is “Error: @redwoodjs/cli tried to access @babel/core, but it isn’t declared in its dependencies; this makes the require call ambiguous and unsound.”

Interestingly, when I run the same command in a native runtime in Render, I don’t see this error.

I’m using RW 8, although the Dockerfile predates the new yarn rw setup docker command:

FROM rust:1.80.0-slim-bookworm as core

RUN apt-get update && \
    apt-get -y install pkg-config libssl-dev && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /rust
COPY core core

WORKDIR /rust/core
RUN mkdir .cargo && \
    cargo vendor > .cargo/config && \
    cargo build --release

FROM node:20-bookworm-slim

RUN corepack enable

RUN apt-get update && \
    apt-get install -y openssl && \
    rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt-get install -y ca-certificates && \
    update-ca-certificates

RUN apt-get update && \
    apt-get install -y python3 python3-pip

WORKDIR /app

COPY --from=core /rust/core/target/release scripts/core

COPY package.json package.json
COPY yarn.lock yarn.lock

COPY redwood.toml redwood.toml
COPY graphql.config.js graphql.config.js

COPY api/package.json api/package.json

RUN yarn install

COPY api api
COPY scripts scripts
RUN yarn rw build api

ENTRYPOINT [ "yarn", "rw", "exec", "jobWorker" ]

Okay, figure this one out on my own. Not sure how applicable this will be to others, but I had this line in my .yarnrc.yml:

yarnPath: .yarn/releases/yarn-3.2.3.cjs

But my package.json had:

"packageManager": "yarn@4.4.0"

I removed the line from .yarnrc.yml and ran yarn install to update yarn.lock, and the issue was resolved.

We also just upgraded to v8, but our Dockerfile for the api builds just fine. Ours looks quite similar, but in addition to your

COPY package.json package.json
COPY yarn.lock yarn.lock

COPY redwood.toml redwood.toml
COPY graphql.config.js graphql.config.js

We also do:

COPY .yarn .yarn
COPY .yarnrc.yml .yarnrc.yml

We still have the original yarnPath. I’m not sure if that would make any difference.