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

mime: incorrect mime-type for .mjs files on windows (text/plain instead of application/javascript) #68591

Open
RPGillespie6 opened this issue Jul 25, 2024 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@RPGillespie6
Copy link

RPGillespie6 commented Jul 25, 2024

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

@ianlancetaylor
Copy link
Member

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?

@RPGillespie6
Copy link
Author

This is what I see in my registry:
image

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.

@dmitshur
Copy link
Contributor

CC @neild.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 26, 2024
@dmitshur dmitshur added this to the Backlog milestone Jul 26, 2024
@nealey
Copy link

nealey commented Oct 4, 2024

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.

@nealey
Copy link

nealey commented Oct 4, 2024

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants