-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev and prod have inconsistent content-types for .ts files #4167
Comments
Is this using |
I encountered this problem when writing a custom service worker in TypeScript, doing something like this:
Everything worked fine with Initially, I came to this issue, since I expected this to work the same in the dev server and a production build. However, I realized this was the wrong way to approach compiling a custom service worker in the first place. Even if the import returned a file path in both situations, it wouldn't get a consistent filename in the prod build - it'd have the content hash in the filename. That means rather than upgrading the service worker when it changed, it'd install a new one side-by-side. And besides that, service workers currently don't support importing ES modules, so for my case I need a separate build pipeline regardless. It'd be nice if Vite offered convenience tools for writing custom service workers, but in the end the right answer for me, rather than faulting this bug, was to create a separate Vite config file for my service worker and add separate build commands for it. |
Have you checked https://github.com/antfu/vite-plugin-pwa? If using Workbox is not good in your case, at least it may be interesting how they solved the service worker handling in Vite. Importing a .ts by URL is not right as you discover, maybe there could be a warning in dev for this case. But I think it isn't possible, since .ts could be a valid video format. Let's close this issue for the moment, and wait for feedback in case others find problems with the current approach. Thanks for bringing this up. |
Describe the bug
.ts
files imported via the*?url
hook have different content-types. In dev, the .ts file is served with the content-typeapplication/javascript
while in prod it is served as avideo/mp2t
dataUri.Related: #2642
Reproduction
https://github.com/kgullion/vite-typescript-audio-worklet-example
The first 2 lines of
src/main.ts
are sufficient for reproduction. I've included a short example for additional context.npm run dev
works as expected butnpm run build && npm run serve
returns the incorrect Content Type for the AudioWorklet. This causesUncaught (in promise) DOMException: The user aborted a request.
in the browser (see: https://stackoverflow.com/a/51469624/992385).System Info
System: OS: Linux 5.12 undefined CPU: (4) x64 Intel(R) Core(TM) i3-4010U CPU @ 1.70GHz Memory: 346.62 MB / 3.74 GB Container: Yes Shell: 5.1.8 - /bin/bash Binaries: Node: 16.2.0 - /usr/bin/node Yarn: 1.22.10 - /usr/bin/yarn npm: 7.15.1 - /usr/bin/npm Browsers: Brave Browser: 91.1.25.68 Chromium: 91.0.4472.77 Firefox: 89.0 npmPackages: vite: ^2.4.0 => 2.4.1
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: