Skip to content
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

vite build: Wrong mime-type (e.g. video/mp2t) when using import workerUrl from './my-worker.js?url syntax #10271

Closed
7 tasks done
schickling opened this issue Sep 28, 2022 · 4 comments
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@schickling
Copy link
Contributor

schickling commented Sep 28, 2022

Describe the bug

When using the ?url worker import syntax e.g. import workerUrl from './my-worker.js?url syntax, Vite currently infers the wrong mime-type. I guess in the case of TS it should re-write it to .js instead like it does for the ?worker behaviour.

image

Reproduction

https://stackblitz.com/edit/vitejs-vite-gjqkkn?file=dist/assets/index.c7da7740.js

System Info

Stackblitz

Used Package Manager

npm

Logs

Output file:

(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))n(e);new MutationObserver(e=>{for(const r of e)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&n(o)}).observe(document,{childList:!0,subtree:!0});function s(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerpolicy&&(r.referrerPolicy=e.referrerpolicy),e.crossorigin==="use-credentials"?r.credentials="include":e.crossorigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(e){if(e.ep)return;e.ep=!0;const r=s(e);fetch(e.href,r)}})();
const i="data:video/mp2t;base64,aW1wb3J0IHsgdmFsIH0gZnJvbSAnLi9jb3VudGVyLmpzJzsKCnNlbGYuYWRkRXZlbnRMaXN0ZW5lcignbWVzc2FnZScsICgpID0+IHsKICBjb25zb2xlLmxvZyhgaGVsbG8gZnJvbSB3b3JrZXIgJHt0ZXN0Lnh9ICR7dmFsfWApOwp9KTsKCm5hbWVzcGFjZSB0ZXN0IHsKICBleHBvcnQgY29uc3QgeCA9ICd0cy1vbmx5LWZlYXR1cmUnOwp9Cg==",l=new Worker(i,{type:"module"});l.postMessage("");

Validations

Related

#2642

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers and removed pending triage labels Sep 28, 2022
@sapphi-red
Copy link
Member

I guess this is a duplicate of #6979.

If you are going to obtain worker url, I think you'll need to use import workerUrl from './my-worker.js?worker&url'.
Because ?url will return the url of a raw file content (TS won't be transpiled, #9952).

@bluwy
Copy link
Member

bluwy commented Sep 28, 2022

Ah yeah looks like so, I should've looked carefully 😅 I'll close this in favor of that then

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2022
@schickling
Copy link
Contributor Author

Thanks for the comments.

Probably another issue but TypeScript doesn't seem to like ?worker&url imports.

@sapphi-red
Copy link
Member

Probably another issue but TypeScript doesn't seem to like ?worker&url imports.

Thanks. Created a PR for it: #10299

@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants