golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.86k stars 17.52k forks source link

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

Open RPGillespie6 opened 1 month ago

RPGillespie6 commented 1 month ago

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

gabyhelp commented 1 month ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

ianlancetaylor commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

CC @neild.