Configure Go Build Constraints in VS Code to work with WebAssembly

Xiaoru Li
InstructorXiaoru Li
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 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.

egghead
egghead
~ 25 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today