Hi,
the solution would be:
1. Protect WASM source files with build flags so that when you open a
"backend" main sources, IDE won't complain about "syscall/js", like this:
// +build js,wasm
2. Open `wasm` directory in second instance of VS Code for which you would
set GOOS and GOARCH for a workspace. When editing settings in json, click
on "workspace" tab and VS Code will create .vscode/settings.json in `wasm`
directory. Put something like:
{
"go.toolsEnvVars": {
"GOOS": "js",
"GOARCH": "wasm",
}
}
in there.
3. In future, work in two instances of VS Code, even though if logically
it's a different parts of same project and could be under the same Go
module. All IDE features will work fluently. I haven't seen any problems
with this approach so far.
суббота, 13 февраля 2021 г. в 23:42:06 UTC+3, [email protected]:
> *(Sorry for posting what is mostly a VSCode question. I've asked it on
> StackOverflow without getting any responses. Am reposting here in the hope
> that some has already run into this problem and figured out how to deal
> with it.)*
>
> I have a Go project that builds a WebAssembly (WASM) app and a backend
> server for it. Both pieces build and run without errors. VSCode, however,
> produces an annoying linter error in the WASM app.
>
> ```
> could not import syscall/js (no required module provides package
> "syscall/js")
> ```
>
> The problem, as I currently understand it, is that VSCode doesn't infer
> from the build tags that it should invoke `gopls` with `env GOOS=js
> GOARCH=wasm` and that one solution is to set these tags as workspace Go
> environment vars.
>
> The app design, however, relies on providing a common internal package to
> both the wasm and the server code so that each side sees some struct
> definitions that simplify the interface between them. To that end, the repo
> is organized (simplified view) as follows:
>
> ```
> cmd
> ├── internal
> │ └── common
> │ ├── common.go
> │ └── common_test.go
> ├── server
> │ └── main.go
> └── wasm
> └── main.go
> ```
>
> How can I configure VSCode to use `env GOOS=js GOARCH=wasm` when linting
> the wasm directory and not for other directories?
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/ed6caf0c-64ec-454d-8926-dc9cbb98d8a5n%40googlegroups.com.