-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Link to stylesheet is transformed to javascript import #8976
Comments
I can't seem to find the issue, but I remember suggesting supporting |
Not sure I understand why I would have to specify that it shouldn't be transformed. When does it make sense for vite to transform a link to a css file to a javascript import? |
It's transformed to an import as Vite sees that it could be resolved to something else. See vite/packages/vite/src/node/plugins/html.ts Lines 356 to 359 in ce790c4
and vite/packages/vite/src/node/plugins/html.ts Lines 227 to 231 in ce790c4
Perhaps something Vite could do is try to resolve the CSS before deciding to transform to an import. That way we don't need |
But it's listed in |
Is there a workaround for this before the fix goes out? |
so, how do we proceed with this error? Our build does not work since it requires a css file that is located at the root directory |
Any news on this? |
Describe the bug
I'm trying to include an external css file in my html, but vite transforms it to an import from the javascript bundle, so I get this error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/css". Strict MIME type checking is enforced for module scripts per HTML spec.
I have this line in
index.html
:In production, the css is available in that location and for development I have included a proxy rule for it, so I would like the line to stay like that in the built html file. When I run
npm run dev
this is what happens and it works. However when I runnpm run build
it removes this line, and instead includes it as an import from the javascript bundle. Since this is a css file, not a javascript file, that fails when the browser tries to load it.Steps to reproduce
npm i
andnpm run build && npm run preview
.If you wonder why I have a rewrite rule to remove
style.css
, this is just because the public font I include in the example is only available on/css
and the issue only seem to happen if what I include has a.css
extension. In my real world use case, the file is actually calledstyle.css
, so then the issue happens without any rewrite rule.Reproduction
https://github.com/trygveaa/vite-external-stylesheet-bug
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: