Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitest fails to start if volume is mounted read-only #4901

Open
6 tasks done
thbley opened this issue Jan 8, 2024 · 2 comments
Open
6 tasks done

vitest fails to start if volume is mounted read-only #4901

thbley opened this issue Jan 8, 2024 · 2 comments
Labels

Comments

@thbley
Copy link

thbley commented Jan 8, 2024

Describe the bug

vitest fails to start if volume is mounted read-only

Reproduction

vitest.config.js

import { defineConfig } from 'vitest/config';

export default defineConfig({
    test: {
        reporters: ['verbose'],
        cacheDir: '/tmp/',
        logHeapUsage: true,
        typecheck: { enabled: true }
    }
});
docker run --rm -it -v $(pwd):/var/www:ro -w /var/www node:20-alpine node_modules/.bin/vitest run
failed to load config from /var/www/vitest.config.js

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
[Error: EROFS: read-only file system, open '/var/www/vitest.config.js.timestamp-1704705432876-13bd1c92cbfa9.mjs'] {
  errno: -30,
  code: 'EROFS',
  syscall: 'open',
  path: '/var/www/vitest.config.js.timestamp-1704705432876-13bd1c92cbfa9.mjs'
}

System Info

node --version v20.10.0

npm list
├── @types/[email protected]
├── [email protected]
└── [email protected]

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 1, 2024

I'm not sure if Vitest (or Vite) is ever intended to run on read-only volume, but this specific error is due to the way Vite loads config file, so I don't think Vitest can do anything about it https://github.com/vitejs/vite/blob/3c9cab6912dc627a22abba4c3fd6074166f5cc4c/packages/vite/src/node/config.ts#L1174

upstream: vitejs/vite#9470

@Lustyn
Copy link

Lustyn commented Feb 9, 2024

Just to add some input from someone who faced and mitigated this issue:

My team was looking into moving our Jest integration test package to Vitest, and the internal platform we use executes test runs in AWS Lambda which similarly to other container runtimes also runs a read only filesystem. A workaround is quite simple however, given /tmp is writable in this case!

The rationale is simple from then forward, for both Vite and Vitest:

  1. Create a new directory in /tmp (ex. /tmp/vitest preferably using tmpdir to generate a name)
  2. Symlink in your project files from the current directory
  3. process.chdir into the symlinked directory
  4. Run Vitest
  5. process.chdir into the original directory
  6. Cleanup your tmp directory if needed

In regards to symlinking node_modules in specific there are two possible solutions:

  1. You can symlink node_modules in a shallow manner, which means it remains read-only and you will need to change the path for test.cache.dir (cacheDir in Vite)
  2. Alternatively, you can symlink node_modules one level deep so that .vitest/.vite can be created for caching.

IMO changing the cache directory is the cleanest solution as symlinking the whole of node_modules could slow down your test run depending on dependency closure.

Thanks to Vitest folks for being diligent about this existing as an upstream issue. It seems Vite has supported loading configs without writing to the filesystem in the past but disabled it due to concerns found on Node 17. I hope we can see those changes introduced again in some form or another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants