Cannot bypass "Corepack is about to download" prompt
I'm trying to run corepack inside devcontainers, in a postCreateCommand.
I've upgraded corepack to latest:
npm install --yes --global corepack@latest
Then run:
corepack -v && COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable
The output I get:
0.29.3
! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.7.1.tgz
? Do you want to continue? [Y/n]
I've tried setting CI too, but also does not work.
Any clues?
I just ran into this, although setting that environment variable worked fine for me. I did this in the Dockerfile. Below is an example, and my full Docker below that if useful.
FROM #...
# ...
RUN corepack enable && corepack install --global [email protected]
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
Full Dockerfile
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04
# Install node
# https://nodejs.org/en/download/prebuilt-binaries
ARG NODE_VERSION="20.17.0"
ARG NODE_CHECKSUM="a24db3dcd151a52e75965dba04cf1b3cd579ff30d6e0af9da1aede4d0f17486b"
RUN wget --https-only "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -O /tmp/node.tar.xz && \
sha256sum /tmp/node.tar.xz | grep "${NODE_CHECKSUM}" && \
tar -C /usr/local -xf /tmp/node.tar.xz --strip-components=1 --exclude="CHANGELOG.md" --exclude="LICENSE" --exclude="README.md" && \
rm /tmp/node.tar.xz && \
corepack enable && \
corepack install --global [email protected]
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
I have the same issue, get hints from this thread, and by removing ~/.nvm, and
sudo npm install --yes --global corepack@latest
then
corepack -v && COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable
the error disapear.
This may be a subtle problem. The doc says COREPACK_ENABLE_DOWNLOAD_PROMPT defaults to 0 (don't prompt) when corepack is triggered explicitly, and defaults to 1 (do prompt) when corepack is triggered implicitly (say by a shim that's configured to download and install a package manager on first use). So something like
corepack install [email protected]
corepack enable pnpm
shouldn't cause an issue, without having to set COREPACK_ENABLE_DOWNLOAD_PROMPT. Conversely, running corepack enable first may install the shims, which later get triggered implicitly. At that point, corepack may be running in a child process that can't see the environment variable passed to the command that triggered it. Setting the environment variable in a Docker container may export it automatically, circumventing this issue.
It does seem that corepack enable is stepping on itself in some circumstances, perhaps by triggering an implicit download through a shim, and thus not seeing the environment variable passed to the parent command. The documentation doesn't include any examples of how to ensure that a given package manager is completely installed and ready to use. It says 'just use your package manager as you normally would.' But that doesn't always work in automated environments, like container setup or CI/CD.
In any case, this works for us in containers during automated setup:
npm install -g --no-update-notifier corepack@latest
corepack install
corepack enable pnpm
echo "pnpm version $(pnpm --version)"
In the above case, the version of pnpm is taken from the package.json file in the current directory (e.g., "packageManager": "[email protected]"). corepack install states it's 'adding pnpm 9.15.3 to the cache' and then corepack enable pnpm silently enables it. YMMV.