vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
65.39k stars 5.81k forks source link

Missmatch between dev / build for typescript files with ?url #16716

Closed anuejn closed 2 weeks ago

anuejn commented 2 weeks ago

Describe the bug

I am trying to import a typescript file with ?url in my application. I would like to get the file back with already stripped types (so as a js file). This is what happens in dev mode. In production mode, the file is left untouched and I get the raw typescript source.

The documentation is not very clear about what should happen, but I would argue, that this missmatch is a bug.

Reproduction

https://stackblitz.com/edit/vitejs-vite-rdougd?file=main.js,test.ts&terminal=dev

Steps to reproduce

  1. Run npm dev to get the typescript compiled to js.
  2. Run npm build && npm preview to get the typescript in its raw form
  3. Observe, that there is a missmatch

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.2.11 => 5.2.11

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 2 weeks ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

sapphi-red commented 2 weeks ago

Duplicate of #6757