Go version
1.21
What did you see happen?
This is identical to #32350 but .mjs instead of .js (I would have commented on the other thread, but it is locked to collaborators only).
.mjs is a fairly common javascript file extension for es modules (example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#aside_%E2%80%94_.mjs_versus_.js)
I'm wondering if it would be acceptable to implement the same workaround found here, but for .mjs?
i.e. I could submit a PR to do:
// There is a long-standing problem on Windows: the
// registry sometimes records that the ".js" extension
// should be "text/plain". See issue #32350. While
// normally local configuration should override
// defaults, this problem is common enough that we
// handle it here by ignoring that registry setting.
if (name == ".js" || name == ".mjs") && (v == "text/plain" || v == "text/plain; charset=utf-8") {
continue
}
What did you expect to see?
.mjs files should not be served with text/plain
due to misconfigured registry
Comment From: gabyhelp
Related Issues and Documentation
- mime: incorrect mime-type for .js files on windows 10 (text/plain instead of application/javascript) #32350 (closed)
- Go 1.19 Release Notes > Core library > Minor changes to the library > mime
- net/http: add built-in mime type for *.mjs #30547 (closed)
- mime: change JavaScript type to text/javascript #32351 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: ianlancetaylor
We added the unfortunate exception after many different people reported it as a bug. This is the first report of a problem with .mjs.
Can you confirm that there is a registry setting on your machine overriding the default .mjs behavior? Do you know where that registry setting came from?
Comment From: RPGillespie6
This is what I see in my registry:
If I delete the Content Type
and PerceivedType
entries, the mime type goes back to application/javascript
as expected.
I have no idea where that registry setting came from. At least 2 devs in my company had it set, while at least 1 didn't have it set. Kind of annoying that arbitrary windows apps can add these entries.
Note that it's not really that big of a deal if we don't fix this because I primarily develop in and deploy to Linux. This just came up recently when some devs were trying to run a go app under windows and getting all the javascript served as plain/text.
It's definitely not as common as .js, but it is common enough that big libraries often release a .mjs version of the library (for example: https://pixijs.download/v8.2.4/pixi.mjs). I created the issue in the off chance other windows users were affected by it, but I'm also fine with just closing the issue as "won't fix" with breadcrumbs to the workaround of amending your registry.
Comment From: dmitshur
CC @neild.
Comment From: nealey
A colleague has this same entry on their Windows 11 machine:
C:\> reg query HKCR\.js /v "Content Type"
HKEY_CLASSES_ROOT\.js
Content Type REG_SZ application/javascript
C:\> reg query HKCR\.mjs /v "Content Type"
HKEY_CLASSES_ROOT\.mjs
Content Type REG_SZ text/plain
My machine has no registry entry for either key. We don't currently have any guesses for what might have modified my colleague's registry to add this bonkers entry.
Comment From: nealey
breadcrumbs to the workaround of amending your registry.
This command will remove the .mjs content-type from a Windows registry, causing Go (and presumably other web servers) to use the IANA-defined media type for these files:
reg delete HKCR\.mjs /v "Content Type"
Comment From: The-Compiler
FWIW, I see a similar issue via Python on Github Action's windows-2022
and windows-2025
images (but windows-2019
wasn't affected, nor is a fresh Windows 11 install). Also no clue where it's coming from, however.
Comment From: mei-rune
https://github.com/golang/go/issues/32350