Skip to content

Intermittent command not found: vite (exit 127) on container startup: a Yarn install-state.gz shared between two containers, and Vite has nothing to do with it

Two containers mounting the same ./.yarn overwrite each other's Yarn install state, and binaries stop being linked. The mechanism, the fix and the check.

Error message
command not found: vite

In short

Symptom
One of the two services dies on startup with vite: not found and exit code 127. The failure is intermittent, it alternates between services, and a restart does not fix it.
Real cause
Both containers mount the same ./.yarn, so the same install-state.gz. Each one writes the state of its own tree. The next one reads a state that does not describe its tree, believes the tree is already installed, and does not recreate the node_modules/.bin links.
Fix
Give each container its own YARN_INSTALL_STATE_PATH, placed inside the volume that holds the tree it describes, and remove the shared ./.yarn mount.
Prevention
No writable volume shared between two services. Mount read-only caches as read-only explicitly, so the question becomes visible in review.

The answer, in three lines

The package is installed. What is missing is its link in node_modules/.bin. Two containers mount the same ./.yarn, so the same install-state.gz, a cache of the install state. Each one rewrites it with the description of its own tree, and the next one believes its tree is already installed on disk when it is not.

The fix: one YARN_INSTALL_STATE_PATH per service, pointing inside the volume that holds the tree it describes, and no more shared ./.yarn mount.

The symptom

When the development environment starts, one of the two services dies:

$ docker compose -f docker-compose.dev.yml up
client-1  | yarn run v4.1.0
client-1  | $ vite --host 0.0.0.0
client-1  | /bin/sh: vite: not found
client-1  | error Command failed with exit code 127.
client-1 exited with code 127
server-1  | [Nest] Starting Nest application...

Three properties, taken together, send the diagnosis the wrong way:

  • The failure is intermittent: one up in three, sometimes one in ten.
  • It alternates: once the client, once the server.
  • A plain restart does not fix it. Once the state is broken it stays broken, and the container comes back only to do exactly the same thing again.

The wrong diagnosis

The lead looks solid: vite is a dev dependency, so you suspect a NODE_ENV=production that pruned the devDependencies, or a node_modules/.bin missing from the PATH.

You open a shell in the container to check, and you find this:

$ docker compose exec client sh
/app # ls node_modules/vite/package.json
node_modules/vite/package.json          # it's there
/app # ls node_modules/.bin/vite
ls: node_modules/.bin/vite: No such file or directory

The package is present, but the binary's symlink is not. At this point the usual suspects are Alpine, symlinks on a Docker volume, or the filesystem driver. Every one of those leads to a dead end, and an expensive one: they push you to rebuild images, change base image, try bind mounts instead of named volumes. The intermittency reinforces the mistake, because a filesystem defect looks intermittent too.

One observation is missing: the failure never happens when a single service starts.

What is actually happening

Two containers share the same Yarn install-state file, and that state describes a node_modules tree that is not theirs.

The offending mount is this one, repeated in both services:

services:
  client:
    volumes:
      - ./.yarn:/app/.yarn        # <-- partagé
      - client_node_modules:/app/node_modules
  server:
    volumes:
      - ./.yarn:/app/.yarn        # <-- le MÊME
      - server_node_modules:/app/node_modules

The node_modules are properly isolated: each service has its own named volume. But ./.yarn contains install-state.gz, which is a cache of the install state. Yarn uses it to know what is already installed on disk, so it does not redo that work.

Here is what happens when both services start at the same time and each runs a yarn workspaces focus on a different part of the repository:

  1. The client installs its part and writes install-state.gz: "the tree contains vite, react, …".
  2. The server installs its own and rewrites the same file: "the tree contains @nestjs/*, typeorm, …".
  3. The client restarts. It reads install-state.gz and finds a state that does not mention its packages, or that describes different ones. It believes its tree is already installed and does not recreate the node_modules/.bin links.
  4. vite exists in node_modules, but its link does not. Exit 127.

The broken state stays in the volume. That explains the most disorienting part: a restart fixes nothing, because the lying file is still there.

This entry shows the "two processes write the same state" failure in its simplest form: the data is isolated, but the metadata that describes it is not.

The fix

Give each container its own install-state path, inside the volume that holds the tree that state describes, and remove the shared mount.

 services:
   client:
+    environment:
+      # l'état vit avec l'arbre qu'il décrit — même chemin, volumes distincts
+      YARN_INSTALL_STATE_PATH: /app/node_modules/.yarn-install-state.gz
     volumes:
-      - ./.yarn:/app/.yarn
       - client_node_modules:/app/node_modules
       - ./yarn.lock:/app/yarn.lock
       - ./.yarnrc.yml:/app/.yarnrc.yml:ro

   server:
+    environment:
+      YARN_INSTALL_STATE_PATH: /app/node_modules/.yarn-install-state.gz
     volumes:
-      - ./.yarn:/app/.yarn
       - server_node_modules:/app/node_modules

The fix holds over time for one reason: the path is identical in both services, but it points into a different volume. The state is therefore destroyed and rebuilt automatically along with the tree it describes, including when you delete only one of the two volumes.

Check (pass or fail)

docker compose down
docker volume rm mon-app_client_node_modules mon-app_server_node_modules
docker compose up -d --build
docker compose logs client --tail=20 | grep -c 'not found'   # doit afficher 0

# le cas qui reproduisait la panne : recréer UN seul service, volume conservé
docker compose up -d --force-recreate client
docker compose logs client --tail=20 | grep -c 'not found'   # doit afficher 0

Prevention

  • In the compose file, write a comment above every shared volume saying why it is shared. If you cannot write that sentence, the volume must not be shared. Read-only caches get mounted :ro, which makes the question obvious.
  • In the repository instruction file, add the rule: "No writable volume shared between two services. Caches and install states belong to each service." That line also covers the services you add later.
  • When you review a compose file, look for volumes: entries whose source appears twice without :ro: grep -o '\- \./[^:]*:' docker-compose*.yml | sort | uniq -d.

Why this matters with agents

This failure is a small copy of the central problem of an agent fleet, meaning several agents working at the same time.

Two containers on shared state is the same situation as N agents on a shared repository. The same four properties show up. The failure is intermittent, because it depends on who writes last. It alternates, with no set victim. It persists, because the corrupted state survives a restart. And neither process is at fault: each one did its job correctly.

The cost is the same too. An agent you send to diagnose this works on a single container and sees nothing but a broken PATH. It offers to reinstall Vite, change the base image, or add a RUN ln -s. Its fix works on the next run and leaves the cause untouched. An agent that does not know two services run at the same time cannot diagnose a failure that comes from it: give it that context in its prompt.

What this entry does not cover

The same exit 127 can come from a package manager that is not the one you think it is. That is a different cause, and it has its own entry.

Where this entry comes from

An incident I hit on a two-container development environment, between February and August 2026. The repository, host names and original paths do not appear here.


This entry is part of a notebook of 27 production failures hit between February and September 2026. Some are public and free: see the notebook.

The others are published as they are written, along with the modules and their exercises, as part of the paid product. In that product, the modules are in English; the exercises and the other entries are in French. Nothing on this page is a teaser for it.

Related notes

The method that handles this kind of failure