How to fix /bin/sh: 1: yarn: not found and corepack: not found on node:lts (Node 26) in Docker
Table of contents
- Key takeaways
- /bin/sh: 1: yarn: not found and exit code 127 when building on node:lts
- The message variants by image and shell
- Why does node:lts no longer ship Yarn or Corepack?
- Fix 1: install Corepack with npm
- Fix 2: install Yarn 1 with npm install -g yarn@1.22.22
- Fix 3: pin node:24 while you migrate
- Gotchas I ran into
- With Corepack and USER node, Yarn is downloaded again at startup
- On Alpine, apk add yarn installs a second Node
- How much space each fix takes
- How to check what your image ships
- FAQ
- Why did my Dockerfile work last week and fail today without any change?
- Is it better to install Corepack or Yarn with npm install -g?
- Can I use npx yarn instead of installing anything?
- Conclusion
- Sources
Since node:lts became Node 26, the official Docker image ships neither Yarn 1 nor Corepack, so RUN yarn install or RUN corepack enable ends with yarn: not found and exit code 127. Add RUN npm install -g corepack@0.36.0 or npm install -g yarn@1.22.22 before it, or pin node:24 while you migrate.
If your docker build fails with /bin/sh: 1: yarn: not found or corepack: not found and exit code: 127, the cause is that node:lts is now Node 26 and that image ships neither Yarn 1 nor Corepack. The fix is one line before your RUN yarn install: RUN npm install -g corepack@0.36.0 && corepack enable if your project pins packageManager, or RUN npm install -g yarn@1.22.22 if all you want is Yarn 1. I reproduced it on 25 November 2026 on arm64 Linux with node:26, node:26-slim and node:26-alpine (Node 26.13.1). There is a Spanish version of this guide.
Key takeaways
- On 25 November 2026,
node:lts,node:latest,node:currentandnode:26are the same image (Node 26.13.1), and the same holds forlts-slimandlts-alpine. - The three Node 26 variants only have
node,npmandnpxin/usr/local/bin; the three Node 24 variants also ship Corepack 0.36.0 and Yarn 1.22.22. - The text changes with the shell:
/bin/sh: 1: yarn: not foundon Debian,/bin/sh: yarn: not foundon Alpine andyarn: command not foundunder bash. npm install -g corepack@0.36.0brings backyarn,yarnpkg,pnpmandpnpx; I tested it with Yarn 1.22.22, Yarn 4.19.0 and pnpm 12.23.0.- With Corepack and
USER node, the container tries to download Yarn at startup;COREPACK_HOMEandcorepack installprevent it.
/bin/sh: 1: yarn: not found and exit code 127 when building on node:lts
This is the failure you see when a Dockerfile starts from a floating tag (node:lts, node:latest, node:26) and calls Yarn without installing it. With this four-line Dockerfile and a package.json with one dependency, the build ends like this:
FROM node:26-slim
WORKDIR /app
COPY package.json ./
RUN yarn install
> [4/4] RUN yarn install:
0.118 /bin/sh: 1: yarn: not found
------
ERROR: failed to build: failed to solve: process "/bin/sh -c
yarn install" did not complete successfully: exit code: 127
Your terminal prints the last two lines as one: process "/bin/sh -c yarn install" did not complete successfully: exit code: 127. Exit code 127 is how a shell reports that it did not find the program. If your Dockerfile enables Corepack before using Yarn or pnpm, the build stops one step earlier with the other message:
> [4/4] RUN corepack enable && yarn install:
0.300 /bin/sh: 1: corepack: not found
------
ERROR: failed to build: failed to solve: process "/bin/sh -c
corepack enable && yarn install" did not complete
successfully: exit code: 127
The message variants by image and shell
The exact text depends on the shell that runs the line, not on Yarn. I built the same Dockerfile on the three Node 26 variants and changed the form of the instruction. These are the messages I got:
| Where | Message |
|---|---|
RUN yarn install on node:26 and node:26-slim |
/bin/sh: 1: yarn: not found, exit code 127 |
RUN yarn install on node:26-alpine |
/bin/sh: yarn: not found, exit code 127 |
RUN corepack enable on node:26-alpine |
/bin/sh: corepack: not found, exit code 127 |
SHELL ["/bin/bash", "-c"] and RUN yarn install on node:26 |
/bin/bash: line 1: yarn: command not found, exit code 127 |
Interactive bash inside node:26 |
bash: yarn: command not found and bash: corepack: command not found |
RUN ["yarn", "install"] on node:26-slim |
exec: "yarn": executable file not found in $PATH, exit code 1 |
CMD ["yarn", "start"] when the container starts |
Error: Cannot find module '/app/yarn', exit code 1 |
The last row never says not found, which makes it the hardest one to trace back. The image's docker-entrypoint.sh passes any command that is not a system program to node. Because yarn no longer exists, node looks for it as a file in the working directory and fails with MODULE_NOT_FOUND. The node:26-alpine image has no bash, so there you will only see the /bin/sh form.
Why does node:lts no longer ship Yarn or Corepack?
Two separate removals meet in Node 26. Node.js stopped bundling Corepack from version 25, and the Node 24 documentation announces it this way: "Corepack will no longer be distributed starting with Node.js v25". The Docker image maintainers also dropped Yarn 1, and the nodejs/docker-node README[1] states it plainly: "Yarn v1 is not bundled into node images as of Node.js 26.0.0". The reason they give is that Yarn 1 is frozen and no longer maintained.
It reaches you now because Node 26 became the long-term support (LTS) line with 26.13.0, released on 28 October 2026. On 25 November I compared the tag digests on mirror.gcr.io: lts, latest, current, 26 and 26.13.1 share one digest, and lts-slim and lts-alpine match 26-slim and 26-alpine. A Dockerfile with FROM node:lts that built on Node 24 now builds on Node 26 without any change on your side.
To see the difference I listed /usr/local/bin and /opt in the six images and asked each package manager for its version:
| Image | Node and npm | Base system | Corepack | Yarn |
|---|---|---|---|---|
node:24 |
24.22.3 and 11.19.1 | Debian 12 | 0.36.0 | 1.22.22 |
node:24-slim |
24.22.3 and 11.19.1 | Debian 12 | 0.36.0 | 1.22.22 |
node:24-alpine |
24.22.3 and 11.19.1 | Alpine 3.24 | 0.36.0 | 1.22.22 |
node:26 |
26.13.1 and 11.20.0 | Debian 13 | absent | absent |
node:26-slim |
26.13.1 and 11.20.0 | Debian 13 | absent | absent |
node:26-alpine |
26.13.1 and 11.20.0 | Alpine 3.24 | absent | absent |
On Node 24, yarn is a link to /opt/yarn-v1.22.22/bin/yarn and the image defines YARN_VERSION=1.22.22. On Node 26, /opt is empty and that variable does not exist. The node:26 and node:26-slim variants also move from Debian 12 to Debian 13, which changes some apt commands; that is a different problem and I leave it out here. The guide to moving your Docker image from Node 24 to Node 26 covers the changes in Node itself.
Fix 1: install Corepack with npm
This is the fix I recommend when your package.json has the packageManager field, because Corepack downloads the exact version the project pins. Add one line before the first call to yarn or pnpm:
FROM node:26-slim
WORKDIR /app
COPY package.json ./
RUN npm install -g corepack@0.36.0 && corepack enable
RUN yarn --version && yarn install
CMD ["yarn", "start"]
On 25 November 2026, 0.36.0 is the latest Corepack version on npm and the same one node:24 ships. With "packageManager": "yarn@1.22.22", the build finished on the three Node 26 variants and the container ran yarn start:
[4/5] RUN npm install -g corepack@0.36.0 && corepack enable
added 1 package
[5/5] RUN yarn --version && yarn install
! Corepack is about to download
https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz
1.22.22
yarn install v1.22.22
success Saved lockfile.
I removed the timings BuildKit prints, and the download line is split in two to fit. I repeated the build on node:26-slim with "packageManager": "yarn@4.19.0" and with "packageManager": "pnpm@12.23.0", and Corepack downloaded each version and installed the project. For pnpm without Corepack, the guide to the --frozen-lockfile error in pnpm 12 uses npm install -g pnpm with a pinned version.
One detail about the package: npm install -g corepack already creates the yarn, yarnpkg, pnpm and pnpx links in /usr/local/bin, because it declares them in its bin field. In my test, corepack enable added none. I keep it in the Dockerfile because it is the command the Yarn install guide asks for, and it does no harm.
Fix 2: install Yarn 1 with npm install -g yarn@1.22.22
If your project is still on Yarn 1 and you do not want Corepack, install Yarn as a global package. It is the path the image README suggests for anyone who still depends on Yarn 1:
FROM node:26-slim
WORKDIR /app
COPY package.json ./
RUN npm install -g yarn@1.22.22
RUN yarn --version && yarn install
CMD ["yarn", "start"]
The build finished on node:26, node:26-slim and node:26-alpine with yarn install v1.22.22. This fix downloads nothing when Yarn runs: the container started without network access and as the node user. Version 1.22.22 is the last Yarn 1 release and dates from March 2024, so pinning it does not leave you behind.
npm 11.20.0 prints a warning during the install: npm warn install-scripts 1 package has install scripts not yet covered by allowScripts, and it names the preinstall of yarn@1.22.22. It blocks nothing and Yarn worked all the same. The guide to allowScripts and min-release-age in npm explains where that warning comes from and how to decide which scripts you approve.
Fix 3: pin node:24 while you migrate
If today you can change only one line of the Dockerfile, replace the floating tag with a Node 24 one. I built the failing Dockerfile, with RUN corepack enable && yarn install, on node:24-slim and it finished unchanged, with Corepack 0.36.0 and Yarn 1.22.22:
FROM node:24-slim
WORKDIR /app
COPY package.json ./
RUN corepack enable && yarn install
This fix has an expiry date. According to the Node.js release schedule[2], Node 24 has been in maintenance since 20 October 2026 and reaches end of life on 30 April 2028. The underlying lesson is to keep node:lts and node:latest out of a Dockerfile: write the major version (node:26-slim) or the full one, and let Dependabot or Renovate propose the bump.
Gotchas I ran into
The first two fixes build on the first try, but I found three cases where the image fails later or grows without telling you.
With Corepack and USER node, Yarn is downloaded again at startup
Corepack stores what it downloads in the home directory of the user that runs it. During the build that user is root, and Yarn ends up in /root/.cache/node/corepack. I started the image from fix 1 with --user node and no network, and the container never got to run yarn start:
! Corepack is about to download
https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz
Error: Error when performing the request to
https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz
[cause]: Error: getaddrinfo EAI_AGAIN registry.yarnpkg.com
With network access, the container downloads Yarn on every start. To avoid that, put the Corepack cache in a shared path and download the package manager during the build with corepack install, which reads packageManager:
FROM node:26-slim
ENV COREPACK_HOME=/usr/local/share/corepack
WORKDIR /app
COPY package.json ./
RUN npm install -g corepack@0.36.0 && corepack enable \
&& corepack install
RUN yarn install
USER node
CMD ["yarn", "start"]
The build printed Adding yarn@1.22.22 to the cache... and left Yarn in /usr/local/share/corepack/v1/yarn/1.22.22. With that image, the container ran yarn start as the node user with --network none.
On Alpine, apk add yarn installs a second Node
On node:26-alpine I also tried the distribution package. apk add --no-cache yarn installed 13 packages, among them nodejs 24.22.3, because the Alpine 3.24 yarn package depends on it. The image ended up with two Node binaries: /usr/local/bin/node at version 26.13.1 and /usr/bin/node at 24.22.3. Yarn answered 1.22.22, but the second binary takes 48,973,184 bytes you do not need, so on Alpine use fix 1 or fix 2 as well.
How much space each fix takes
Neither fix changes the image size in a way you would notice. I measured with du -sk what each one adds to node:26-slim and compared it with the Yarn that node:24-slim shipped in /opt:
The three figures sit between 5.1 and 5.9 MiB. According to docker images, node:26-slim takes 374 MB and the images with each fix take 387 and 388 MB, test application included.
How to check what your image ships
Before you change the Dockerfile, look at which package managers the tag you use has. This command lists the programs in /usr/local/bin and works on the three variants:
$ docker run --rm node:26-slim sh -c 'ls /usr/local/bin | xargs'
docker-entrypoint.sh node nodejs npm npx
$ docker run --rm node:24-slim yarn --version
1.22.22
If yarn and corepack are missing from the list, this guide is about your case. After the fix, docker run --rm your_image yarn --version must answer with the version your package.json pins, and docker run --rm --network none your_image must start without downloading anything.
FAQ
Why did my Dockerfile work last week and fail today without any change?
Because node:lts is a floating tag and it now points to Node 26. Node 26 has been LTS since version 26.13.0, released on 28 October 2026, and its image has shipped no Yarn or Corepack since 26.0.0. Your continuous integration (CI) server pulls the tag again when it is not in its cache, and that day it moves from Node 24 to Node 26.
Is it better to install Corepack or Yarn with npm install -g?
Corepack, if your project uses Yarn 2 or later or pnpm, or if it already pins packageManager: one line covers the three package managers and respects the project's version. npm install -g yarn@1.22.22 is enough if you stay on Yarn 1 and want an image that downloads nothing at startup. The Yarn documentation on Corepack[3] advises against npm install -g yarn because it installs whatever version was published last, which is why fix 2 pins the version.
Can I use npx yarn instead of installing anything?
It works, but it downloads Yarn on every run. On node:26-slim, npx --yes yarn --version answered 1.22.22 after fetching the package from the npm registry. In a Dockerfile, a layer with the pinned version is the better choice: the build cache keeps it and it does not depend on the network at startup.
Conclusion
The error is not in your project: node:lts moved to Node 26 and the official image no longer ships Yarn 1 or Corepack. Add RUN npm install -g corepack@0.36.0 && corepack enable if you pin packageManager, or RUN npm install -g yarn@1.22.22 if you stay on Yarn 1. If the container runs with USER node, set COREPACK_HOME and run corepack install in the build. And replace node:lts with a tag that names the major version, so that you decide when the next LTS jump happens.
Sources: [1] nodejs/docker-node, README: Yarn v1 Classic bundling[1], [2] Node.js 24, Corepack documentation[4], [3] Node.js 26.13.0 (LTS), release notes[5], [4] nodejs/corepack, install with npm[6], [5] Yarn, Corepack documentation[3], [6] Yarn 1, installation instructions[7], [7] nodejs/Release, release schedule[2], [8] nodejs/docker-node, docker-entrypoint.sh[8].
Sources
Source code
Access all the source code for this post on GitHub.
View on GitHub