pi0 / nuxt-build-cache

▣ Speed up your Nuxt builds up to 2x [experimental]
150 stars 1 forks source link

Vitest conflict when cache is present #5

Open FranckKe opened 7 months ago

FranckKe commented 7 months ago

There seems to be an issue with Vitest when a cache is present

Reproduction

Reproduction repo: https://github.com/FranckKe/nuxt-cache-vitest

❯ pnpm version
{
  npm: '10.2.4',
  node: '20.11.1',
  acorn: '8.11.2',
  ada: '2.7.4',
  ares: '1.20.1',
  base64: '0.5.1',
  brotli: '1.0.9',
  cjs_module_lexer: '1.2.2',
  cldr: '43.1',
  icu: '73.2',
  llhttp: '8.1.1',
  modules: '115',
  napi: '9',
  nghttp2: '1.58.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.13+quic',
  simdutf: '4.0.4',
  tz: '2023c',
  undici: '5.28.3',
  unicode: '15.0',
  uv: '1.46.0',
  uvwasi: '0.0.19',
  v8: '11.3.244.8-node.17',
  zlib: '1.2.13.1-motley-5daffc7'
}

First run works as expected

pnpm i
pnpm run test
# Tests run fine
pnpm i
pnpm run dev
pnpm run test
[error] [nitro] Error: Could not load /home/myuser/workspace/nuxt-cache-vitest/.nuxt/dist/server/styles.mjs (imported by node_modules/.pnpm/nuxt@3.11.2_@unocss+reset@0.59.0_floating-vue@5.2.2_unocss@0.59.0_vite@5.2.8/node_modules/nuxt/dist/core/runtime/nitro/renderer.js): ENOENT: no such file or directory, open '/home/myuser/workspace/nuxt-cache-vitest/.nuxt/dist/server/styles.mjs'

undefined

failed to load config from /home/myuser/workspace/nuxt-cache-vitest/vitest.config.ts
Unhandled Error 
[Error: Could not load /home/myuser/workspace/nuxt-cache-vitest/.nuxt/dist/server/styles.mjs (imported by node_modules/.pnpm/nuxt@3.11.2_@unocss+reset@0.59.0_floating-vue@5.2.2_unocss@0.59.0_vite@5.2.8/node_modules/nuxt/dist/core/runtime/nitro/renderer.js): ENOENT: no such file or directory, open '/home/myuser/workspace/nuxt-cache-vitest/.nuxt/dist/server/styles.mjs']
pnpm i
pnpm run build
pnpm run test
# Silently fails, seems to run "pnpm run build" again
> nuxt-app@ test /home/myuser/workspace/nuxt-cache-vitest
> vitest

[success] [nitro] Generated public .output/public
[info] [nitro] Building Nuxt Nitro server (preset: `node-server`)
[success] [nitro] Nuxt Nitro server built
  ├─ .output/server/chunks/_/error-500.mjs (5.09 kB) (2.12 kB gzip)
  ├─ .output/server/chunks/_/error-500.mjs.map (240 B) (174 B gzip)
  ├─ .output/server/chunks/build/client.manifest.mjs (2.49 kB) (519 B gzip)
  ├─ .output/server/chunks/build/client.manifest.mjs.map (1.61 kB) (374 B gzip)
  ├─ .output/server/chunks/routes/renderer.mjs (11.8 kB) (3.83 kB gzip)
  ├─ .output/server/chunks/routes/renderer.mjs.map (665 B) (294 B gzip)
  ├─ .output/server/chunks/runtime.mjs (165 kB) (40.1 kB gzip)
  ├─ .output/server/chunks/runtime.mjs.map (4.38 kB) (939 B gzip)
  ├─ .output/server/chunks/virtual/_virtual_spa-template.mjs (94 B) (100 B gzip)
  ├─ .output/server/chunks/virtual/_virtual_spa-template.mjs.map (112 B) (111 B gzip)
  ├─ .output/server/index.mjs (291 B) (192 B gzip)
  └─ .output/server/package.json (741 B) (309 B gzip)
Σ Total size: 1.56 MB (375 kB gzip)
[success] [nitro] You can preview this build using `node .output/server/index.mjs`

Workarounds

rm -rf node_modules .nuxt .output
pnpm i
pnpm run test

or

NUXT_DISABLE_BUILD_CACHE=true pnpm run test
pi0 commented 6 months ago

/cc @antfu Do you know if vitest scans whole node_modules/.cache/** dir? We use node_modules/.cache/nuxt currently.