2

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 () { fmt.Println("test") } 

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!

1 Answer 1

3

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.

???

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.