scripts with a src attribute that's not a known extension aren't recognized as js
See original GitHub issueDescribe the bug
I am writing a vite plugin for Imba and it works great.
However, I cannot use <script type="module" src="/src/main.imba"></script>
in the index.html.
The browser complains about
main.imba:1
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
Note that other imports work fine
Reproduction
https://stackblitz.com/edit/vitejs-vite-nxtcgv?file=vite.config.js,index.html,main.imba&terminal=dev
System Info
System:
OS: macOS 12.4
CPU: (10) arm64 Apple M1 Max
Memory: 331.89 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.11.0 - /usr/local/bin/npm
Browsers:
Chrome: 104.0.5112.101
Chrome Canary: 107.0.5275.0
Safari: 15.5
Used Package Manager
npm
Logs
Click to expand!
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
How can I get the content of the file specified as the 'src' of a ...
I've looked to use this technique for client side error logging (of javascript exceptions) after getting "undefined variables" which aren't ...
Read more >Working with JavaScript in Visual Studio Code
Working with JavaScript. This topic describes some of the advanced JavaScript features supported by Visual Studio Code. Using the TypeScript language ...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >Content Security Policy (CSP) Bypass - HackTricks
script -src: This directive specifies allowed sources for JavaScript. This includes not only URLs loaded directly into elements, but also things like inline ......
Read more >What causes a Script error and how to solve them · Raygun Blog
Script errors occur when a client-side script that violates the same-origin policy of the user's browser by making an invalid cross-origin ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It would be nice if we could read the
Sec-Fetch-Dest
header as part ofisJSRequest
and apply transforms if it is set toscript
, but of course Safari doesn’t support it: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-DestEdit: the webkit bug for the implementation was fixed earlier this year and it ships in the Safari nightly builds, according to bugzilla: https://bugs.webkit.org/show_bug.cgi?id=204744. Also, Vite already reads
sec-fetch-dest
in the indexHtml middleware for the spa fallback@patak-dev, what do you think?
This code is guarding the transform:
Since
isJSRequest
is not customizable, it returnsfalse
for.imba
files. However, you can take advantage of the second condition and mark the request as an import by adding the?import
query param:With this it works without any additional config! (besides the
.imba
file transform)And as per https://github.com/vitejs/vite/pull/3828#issuecomment-875403352, maybe suggest adding
.imba
to the known JS type extensions?