apps/web preview overwrites newly built dist/index.html with stale dist/index.html.bak across builds

Aperta Adatta ai principianti
#1,938 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript, vite

Direzione di ricerca

Inizia con apps/web/package.json:8 (build) e apps/web/package.json:11 (preview), poi con apps/web/vite.config.ts:43 dove è impostato emptyOutDir: false; confronta gli script di build di apps/api/package.json e apps/gateway/package.json per il pattern di pulizia. Nota che turbo.json:11 mette in cache dist/**, per questo il .bak obsoleto sopravvive. Completato quando un secondo pnpm test:e2e dopo una modifica al codice serve i chunk con hash appena emessi, verificato ispezionando i tag <script> in apps/web/dist/index.html.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Area: Infrastructure Area: Web Bug Difficulty: Low Priority: Medium

apps/web/vite.config.ts:43 sets build.emptyOutDir: false, and apps/web/package.json:8 ("build": "tsc && NODE_ENV=production NODE_OPTIONS='--import=tsx' pnpm exec vite build") does not remove dist before building.

When pnpm test:e2e starts apps/web's preview script (apps/web/package.json:11):

env-cmd -f ../../.env -- pnpm exec import-meta-env -x .env.public -p dist/index.html && NODE_OPTIONS='--import=tsx' env-cmd -f ../../.env pnpm exec vite preview

@import-meta-env/cli saves a backup of dist/index.html to dist/index.html.bak on the first run and, whenever dist/index.html.bak already exists, reads dist/index.html.bak as its template and overwrites dist/index.html with it.

Because vite build has emptyOutDir: false:

  1. Subsequent pnpm build runs write a new dist/index.html and new content-hashed dist/assets/*.js chunks, while leaving the old dist/index.html.bak and old dist/assets/*.js files in apps/web/dist/.
  2. Turbo caches dist/** (turbo.json:11), including the stale dist/index.html.bak.
  3. On the next pnpm test:e2e run, import-meta-env overwrites the newly built dist/index.html with the stale dist/index.html.bak, so vite preview serves the old hashed JS chunks from an earlier build or branch instead of the current apps/web code.
Reproduction
  1. Run pnpm test:e2e (which creates apps/web/dist/index.html.bak via pnpm preview).
  2. Change code in apps/web (or switch branches) and run pnpm test:e2e again without rm -rf apps/web/dist.
  3. Inspect apps/web/dist/index.html after pnpm preview starts: its <script> and <link rel="modulepreload"> tags match apps/web/dist/index.html.bak from step 1 rather than the newly emitted chunks from step 2.
Possible fix

Clean dist before vite build in apps/web/package.json (matching apps/api/package.json and apps/gateway/package.json, or enable emptyOutDir: true if runtime plugin ordering allows it) or remove dist/index.html.bak during apps/web build.

Lingua principale
TypeScript
Stelle
119
Fork
19
Merge medio
1g 18h
PR unite (30g)
60

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DouglasNeuroInformatics/OpenDataCapture

Tutte le issue di DouglasNeuroInformatics/OpenDataCapture

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.