Skip to content

Web Workers in TypeScript have incorrect source map #14216

Closed
@yume-chan

Description

@yume-chan

Describe the bug

When using new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }) to load a Web Worker, the worker script has incorrect source map.

Reproduction

https://stackblitz.com/edit/vitejs-vite-f2cvz7?file=counter.js,worker.ts&terminal=dev

Steps to reproduce

  1. Open DevTools
  2. Reload the preview page
  3. DevTools will automatically show source for worker.ts
  4. Try to set a breakpoint at line 5 (console.log('small');)
  5. The breakpoint is at line 6

System Info

System:
    OS: Windows 10 10.0.25936
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 11.50 GB / 31.91 GB
  Binaries:
    Node: 18.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.5 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (116.0.1938.62)
    Internet Explorer: 11.0.25936.1000
  npmPackages:
    vite: ^4.4.6 => 4.4.6

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: web workersp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions