golang build constraints exclude all Go files in


I build a simple "Hello, World" wasm app like:

GOARCH=wasm GOOS=js go build -o lib.wasm main.go

All is well. But then I want to test my code in my local (Linux) environment. So I change it to a pretty standard:

package main

import "fmt"

func main () {

And do a simple:

go run .

but now I get:

package xxx: build constraints exclude all Go files in xxx

I understand that if I specify a wasm build, I can’t expect to run it locally. But I’m not trying to do a wasm build anymore. There are no build constraints in my .go source file, and my go.mod file just has the package and go version.

If I copy these file to a new directory and only do the go run . without the wasm build – all is good.

And if I do:

go build filename.go

it works properly.

It’s like something "remembers" that this directory was supposed to be built with wasm – but I cant find what/where.

Is there a cache or something elsewhere that’s remembering some build settings that I need to clear? I’ve tried go clean and go clean -cache – no luck!


The answer seems to be that if a filename ends in wasm.go – go will assume this is indeed a wasm file.

This means that a normal build or run will fail (if you don’t specify proper OS and arch) – though a run with an explicit filename (even if it ends in wasm.go will work correctly.


Answered By – Brad

Answer Checked By – Willingham (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.