Repository navigation
Description
Describe the bug
Since 5.0.4 fsModuleCache is on by default (#11435). When the project directory is not writable, Vitest fails every test file instead of running without the cache:
FAIL sum.test.js [ sum.test.js ]
Error: ENOENT: no such file or directory, mkdir '/app/node_modules/.vitest-cache'
On a non-root user over a root-owned project the same happens with EACCES: permission denied, mkdir '<root>/node_modules/.vitest-cache'.
The cache is an optimization, but mkdirSync(cacheRoot, { recursive: true }) in FileSystemModuleCache has no error handling (fsModuleCache.ts at v5.0.5), so a failed directory creation turns into a failed suite. The same setup passes on 5.0.3.
Where this hits: read-only container root filesystems, sandboxes that mount the project read-only and run tests as another user, CI with a pre-installed node_modules owned by root. In our case (an education platform running student exercises in locked-down containers) every JS exercise broke after bumping to 5.0.5. --no-fsModuleCache or fsModuleCachePath work around it, but each project has to know about it, and there is no environment variable to set it once per image.
Suggested fix: if the cache directory cannot be created or written (EACCES, EPERM, EROFS, ENOENT on a read-only fs), log a single warning and continue with the fs module cache disabled. I'm happy to send a PR with a test if this direction is accepted.
Reproduction
FROM node:24-slim
ARG V=5.0.5
WORKDIR /app
RUN echo '{"type":"module"}' > package.json && npm i -D vitest@${V} \
&& echo "import { test, expect } from 'vitest'; test('ok', () => expect(1).toBe(1))" > sum.test.jsdocker build -t vitest-ro --build-arg V=5.0.5 .
docker run --rm --read-only --tmpfs /tmp -e HOME=/tmp vitest-ro npx vitest run
# FAIL sum.test.js Error: ENOENT: no such file or directory, mkdir '/app/node_modules/.vitest-cache'
docker run --rm --read-only --tmpfs /tmp -e HOME=/tmp vitest-ro npx vitest run --no-fsModuleCache
# Tests 1 passed
docker build -t vitest-ro-503 --build-arg V=5.0.3 .
docker run --rm --read-only --tmpfs /tmp -e HOME=/tmp vitest-ro-503 npx vitest run
# Tests 1 passed(HOME=/tmp is needed because the API token is written under $HOME or node_modules/.vitest; without it startup fails earlier with a similar error, which may be worth the same treatment.)
System Info
Docker image node:24-slim (Debian), Node.js 24, vitest 5.0.5; host Linux 6.8Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Activity
github-actions commentedon Oct 28, 2026
This issue is approved, so the team accepts a pull request for it. To work on it, open a pull request against
mainand link this issue in its description with a closing keyword, for exampleFixes #11777.The team accepts one pull request per issue: if another pull request for this issue is already open, a new one is closed automatically. See our pull request policy for more context.
OKAN-SOFTWARE commentedon Oct 28, 2026
I'm interested in contributing a focused fix for this issue, including regression coverage for read-only project directories. I see the issue is approved. Before I begin, could you confirm whether a PR is already being prepared?