Skip to content

vite config files can't be compiled without dom types #9813

Closed
@DetachHead

Description

@DetachHead

Describe the bug

when attempting to compile a vite.config.ts file without dom types, and without skipLibCheck in tsconfig.json, the following errors occur:

❯ tsc
node_modules/esbuild/lib/main.d.ts:592:16 - error TS2503: Cannot find namespace 'WebAssembly'.

592   wasmModule?: WebAssembly.Module
                   ~~~~~~~~~~~

node_modules/vite/dist/node/index.d.ts:1259:13 - error TS2304: Cannot find name 'Worker'.

1259     worker: Worker
                 ~~~~~~


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/esbuild/lib/main.d.ts:592
     1  node_modules/vite/dist/node/index.d.ts:1259

i believe it's because these types are defined globally in lib.dom.d.ts. but since the vite.config.ts file is executed by nodejs, it's incorrect to include the dom types when compiling it.

is it possible to resolve this by importing the Worker type from elsewhere?

Reproduction

https://stackblitz.com/edit/vitejs-vite-ghpgs3?file=vite.config.ts,tsconfig.json,package.json&terminal=dev

System Info

❯ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
ERR!: Failed to install package

error Command failed with exit code 1

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions