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

Open Beginner friendly
#1,938 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript, vite

Research direction

Start with apps/web/package.json:8 (build) and apps/web/package.json:11 (preview), then apps/web/vite.config.ts:43 where emptyOutDir: false is set; compare the build scripts of apps/api/package.json and apps/gateway/package.json for the cleaning pattern. Note turbo.json:11 caches dist/**, which is why the stale .bak survives. Done when a second pnpm test:e2e after a code change serves the newly emitted hashed chunks, verified by inspecting the <script> tags in apps/web/dist/index.html.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
119
Forks
19
Avg merge
1d 18h
Merged PRs (30d)
60

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DouglasNeuroInformatics/OpenDataCapture

All issues in DouglasNeuroInformatics/OpenDataCapture

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.