If you encounter the error Corepack is about to download ...
during your CI pipeline setup, it’s likely caused by a cached or mismatched version of pnpm
and the absence of a packageManager
field in your project. Here’s how to resolve this issue efficiently.
Issue Example:
You might see logs similar to this in your CI pipeline:
#12 [prod 5/7] RUN pnpm fetch --prod
#12 0.353 ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.14.2.tgz
#12 0.972 ! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing ...
This happens because Corepack cannot determine which version of pnpm
to use, and it defaults to attempting a download. This behavior disrupts CI workflows.
Root Cause
- Missing
packageManager
Field: Your project doesn’t explicitly define whichpnpm
version to use. - Corepack Download Prompt: Corepack attempts to download
pnpm
but requires confirmation, which fails in non-interactive CI environments. - Cached or Outdated pnpm Version: The CI environment might have cached an incompatible
pnpm
version.
Solution
Add the following steps to your Dockerfile or CI pipeline to ensure a consistent pnpm
installation and prevent Corepack from prompting for downloads.
Dockerfile Configuration
# Enable Corepack
RUN corepack enable
# Install a specific version of pnpm globally
RUN corepack prepare pnpm@9.8.0 --activate
# Disable Corepack download prompts
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
Explanation of Commands
corepack enable
: Activates Corepack, enabling it to manage package managers likepnpm
.corepack prepare pnpm@9.8.0 --activate
: Installs and globally activates the specifiedpnpm
version.ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
: Prevents Corepack from prompting for downloads, making it CI-friendly.
Adding packageManager
Field
To prevent the error entirely, add a packageManager
field to your package.json
:
{
"name": "your-project",
"version": "1.0.0",
"packageManager": "pnpm@9.8.0"
}
This ensures Corepack knows which version of pnpm
your project requires.
Examples:
Dockerfile for nodejs application
Here’s a complete Dockerfile example:
FROM node:18-alpine
# Enable Corepack and set pnpm version
RUN corepack enable
RUN corepack prepare pnpm@9.8.0 --activate
# Disable Corepack download prompts
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
# Set work directory
WORKDIR /app
# Copy project files
COPY . .
# Install dependencies and build
RUN pnpm install
RUN pnpm build
Dockerfile for NestJS application
FROM node:20-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack install --global pnpm@8.15.4
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
FROM base AS prod
WORKDIR /app
COPY package.json /app
COPY tsconfig.json /app
COPY pnpm-lock.yaml /app
RUN pnpm fetch --prod
COPY . /app
# Install nestjs cli
RUN pnpm install -g @nestjs/cli
# Install the dependencies
RUN pnpm install --prod
# Build the nestjs app
RUN pnpm run build
FROM base
COPY --from=prod /app/node_modules /app/node_modules
COPY --from=prod /app/dist /app/dist
COPY --from=prod /app/package.json /app/package.json
COPY --from=prod /app/pnpm-lock.yaml /app/pnpm-lock.yaml
COPY --from=prod /app/tsconfig.json /app/tsconfig.json
WORKDIR /app
EXPOSE 3000
CMD [ "pnpm", "start" ]
Verifying in CI
- Check that
pnpm
is installed with the correct version by running:pnpm --version
- Ensure your pipeline passes without prompting for Corepack downloads.
By following these steps, you can avoid errors related to pnpm
installation in CI environments and maintain a smooth workflow.