Configure Go Build Constraints in VS Code to work with WebAssembly

Xiaoru Li
InstructorXiaoru Li

Share this video with your friends

Send Tweet
Published 3 years ago
Updated 2 years ago

Go ^1.12

When using Go modules related to WebAssembly, namely syscall/js, the default settings in VS Code will trigger error reports like "Build constraints exclude all Go files" in the editor. In this lesson, we will learn how to fix this and improve our coding experience.

Xiaoru Li: [00:00] The syscall/js module is crucial for making any Go code interact with JavaScript through WebAssembly. As you can see, the default settings in VS Code will trigger this build constraints error message. Because this is a VS Code problem, we are still able to compile our code to wasm binary in the terminal.

[00:22] Let's fix this error message by updating our VS Code settings, which was Workspace instead of the Global user settings, because we still want to write Go code for non-WebAssembly projects. Then, search for go tools env variables and select editing settings.json.

[00:42] Similar to what we did in the terminal we can set GOOS to js and GOARCH to wasm. Then, save the settings and reload the VS Code window. Now, the error message is gone.