gowebassemblygoland

How to setup Goland (or any other jetbrains product) for WASM development with Golang


I’m trying to set up GoLand for Go development, specifically for compiling WebAssembly (WASM) files. I’m running into an issue that I hope someone can help me with.

When I attempt to import the syscall/js package in my Go code, I receive the following error:

build constraints exclude all Go files in 'Ilusr/local/go/src/syscall/js'.

To resolve this, I added the following build constraint at the top of my Go file:

//go:build js && wasm

This change allowed me to bypass the error, but unfortunately, it led to a new problem: I no longer have access to GoLand's documentation and code suggestions. This is a significant setback for my development process as I rely heavily on these features for writing and navigating my code.


Solution

  • Configuring GoLand for WebAssembly (Wasm) projects

    Initial project configuration

    When you first open or start a WebAssembly project in GoLand, it won'’t understand the “syscall/js” package. That’s easily fixable, by changing the GOOS and GOARCH values in the project settings, as shown in the below screenshots.

    enter image description here

    The screenshot below shows how to access Settings on a Linux desktop. If you're using macOS, you'll probably need to access them through the standard macOS Preferences option. GoLand Wasm.

    enter image description here

    enter image description here

    enter image description here

    Configuring Run/Debug settings

    With the initial project settings changed, you'll probably want to configure the Run/Debug settings next.

    That will let you recompile the .wasm file by just launching Run (Shift+F10 on Linux).

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    Finished, your GoLand setup should now be complete.

    Source: Go Wiki: Configuring GoLand for WebAssembly