Skip to content

.wxt/tsconfig.json is cleared and overwritten on rebuild #897

@hikiko4ern

Description

@hikiko4ern

Describe the bug

When rebuilding, findEntrypoints is called, which overwrites .wxt/tsconfig.json with the {}:

await fs.writeJson(resolve(wxt.config.wxtDir, 'tsconfig.json'), {});

which is later overwritten in generateTypesDir with the newly generated content:
entries.push(await getTsConfigEntry());

For a large enough project, it may take 1-2 seconds between two file writes. The TypeScript Server, which watches for changes to .wxt/tsconfig.json, will see the first change to {} (from findEntrypoints) and rebuild the project, and since .wxt/wxt.d.ts will not be included in the project, the code editor will show errors like

Cannot find name 'defineContentScript'. ts(2304)

until the TS project is rebuilt again after writing the generated .wxt/tsconfig.json from generateTypesDir.

This is what it looks like in the code editor:

save.mp4

I have tried changing (hikiko4ern@5e9d43e) the fs.writeJson flag from w to wx so that the file is not overwritten when present, and the problem does not reproduce and the tests pass, but I'm not sure if that breaks something.

Reproduction

https://github.com/hikiko4ern/wxt-tsconfig-truncated

Steps to reproduce

  1. pnpm i
  2. pnpm dev
  3. save any file to trigger rebuild (e.g. entrypoints/dummy1.content.ts)

System Info

System:
  OS: Linux 5.15 Debian GNU/Linux trixie/sid
  CPU: (32) x64 AMD Ryzen 9 7950X3D 16-Core Processor
  Memory: 54.69 GB / 64.76 GB
  Container: Yes
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.15.1 - /mnt/wslg/runtime-dir/fnm_multishells/13782_1722726260960/bin/node
  npm: 10.7.0 - /mnt/wslg/runtime-dir/fnm_multishells/13782_1722726260960/bin/npm
  pnpm: 9.6.0 - /mnt/wslg/runtime-dir/fnm_multishells/13782_1722726260960/bin/pnpm
  bun: 1.1.8 - ~/.bun/bin/bun
Browsers:
  Chrome: 127.0.6533.72
  Chromium: 123.0.6312.105
npmPackages:
  wxt: ^0.19.3 => 0.19.3

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions