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

WebAssembly not executing/compiling due to incorrect response MIME type. Expected 'application/wasm'. #40029

Closed
bbloks opened this issue Jul 3, 2020 · 6 comments

Comments

@bbloks
Copy link

@bbloks bbloks commented Jul 3, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.4 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/bbloks/.cache/go-build"
GOENV="/home/bbloks/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/bbloks/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
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-build048412657=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Creating a simple webserver and trying to implement WebAssembly.
Considering following folder structure:

├── lib.wasm
├── main.go
├── public
│ └── wasm_exec.js
├── README.md
└── templates
└── index.html

Replicated issue and made available in this public repo: https://github.com/bbloks/golang-wasm-issue-repl

OS: Ubuntu 18.04.3 LTS

What did you expect to see?

No error, webassembly just loading properly

What did you see instead?

FireFox: Mozilla Firefox 78.0.1, displays error in console:
TypeError: Response has unsupported MIME type

Chromium: 83.0.4103.61, displays error in console:
TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

@frvannes16
Copy link

@frvannes16 frvannes16 commented Jul 3, 2020

What are you using to serve your main.wasm file?
I don't think it has support for the application/wasm mimetype

@frvannes16
Copy link

@frvannes16 frvannes16 commented Jul 3, 2020

You can write your own golang server that can serve your files with a little bit of go:

package main

import (
	"log"
	"net/http"
	"os"
	"strings"
)

func main() {
	if len(os.Args) != 2 {
		log.Fatal("Not enough arguments provided. Please provide the file serving directory.")
	}
	dir := os.Args[1]
	fs := http.FileServer(http.Dir(dir))
	log.Print("Serving " + dir + " on http://localhost:8080")
	http.ListenAndServe(":8080", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		log.Println(req.URL)
		resp.Header().Add("Cache-Control", "no-cache")
		if strings.HasSuffix(req.URL.Path, ".wasm") {
			resp.Header().Set("content-type", "application/wasm")
		}
		resp.Header().Set("Access-Control-Allow-Origin", "*")
		fs.ServeHTTP(resp, req)
	}))
}

And then you can run that code with go run main.go [file server directory]

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 3, 2020

http.FileServer should be serving files with .wasm extension as "application/wasm" since Go 1.11, see commit 534ddf7.

Is it possible your /etc/mime.types or another similar file overrides it to something else?

What does this program print for you? It should be "application/wasm". If not, check your local MIME files(/etc/mime.types, /etc/apache2/mime.types, /etc/apache/mime.types).

@bbloks
Copy link
Author

@bbloks bbloks commented Jul 4, 2020

@dmitshur, indeed I was expecting the server to automatically recognize and serve as "application/wasm".

Running the mentioned go playground program prints "application/wasm", so there it is working correctly.

A check on /etc/mime.types on my Ubuntu machine (although I never made any adjustments to it) showed application/wasm wasm is not in the list. Also grep 'wasm' /etc/mime.types did not return anything, so I'm sure I did not accidentally overlook it.

I tried by adding the mime type application/wasm wasm to /etc/.mime.types, saved and restarted, however then the error still persists.

@frvannes16, running your example I get the same error in the browser console.

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 9, 2020

Running the mentioned go playground program prints "application/wasm", so there it is working correctly.

What about if you run the same program on your computer, what does it print then?

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 16, 2020

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.