Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.12 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/daniel/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/daniel/.go" GOPROXY="" GORACE="" GOROOT="/usr/lib/go" GOTMPDIR="" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build067538039=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Given a folder with the following files:
index.html:
<html>
<body>
<script type="module" src="test.mjs"></script>
</body>
</html>
and test.mjs (see: https://developers.google.com/web/fundamentals/primers/modules)
console.log("hi!");
My code serves the above with http.FileServer
, and I navigate to /
in my browser, opening index.html
What did you expect to see?
I expected hi
to be printed in the javascript console
What did you see instead?
The following error in chrome:
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
This is because .mjs
is not a recognized mimetype. This can easily be worked around by manually adding .mjs
to the mime database:
mime.AddExtensionType(".mjs", "application/javascript")
Or, technically, one can just use .js
- but .mjs
seems to be commonly used.
However, since es modules are a standard, and will become more common in the future, it would be nice to have the mimetype built in.