Golang unrecognized import path “syscall/js”


(Easy Developer) #1

I am trying to use webassembly but I can’t run this

import (
    "syscall/js"
)

or

GOARCH=wasm GOOS=js go get -u github.com/siongui/godom/wasm

to install wasm

It throws me an error

cannot find package "syscall/js" in any of:

Thanks a lot


(Jay Ts) #2

Hi,

The syscall/js package is new with Go version 1.11. Make sure you have a recent version of Go installed. Version 1.11 was released in August, 2018. (The go version command reports what version of Go is installed.)

Other than that, you do not need to install anything for WebAssembly support. Look in $GOROOT/misc/wasm for wasm_exec.js, which is most of the JavaScript glue code you need to load your wasm file. There is also some JavaScript that needs to go in your HTML file to loadwasm_exec.js, and that loads your wasm executable.

I have some more comments about these things in other forum topics, and I have two examples at my GitHub site:

https://github.com/Yaoir/ClockExample-Go-WebAssembly
https://github.com/Yaoir/VideoPoker-Go-WebAssembly

I made the Clock web app really simple to help other people get started with WebAssembly. The Video Poker app does a lot more. Look near the end of the README for information about building WebAssembly apps.

Also take a look at this page if you haven’t yet: https://github.com/golang/go/wiki/WebAssembly


(Easy Developer) #4

hi Jay! Thank you so much for your time responding my question. I did run go version and my version is “go1.6.2 linux” but still syscall/js is not found. I still have syscall though


(Jay Ts) #5

1.6.2 is too old! Time to upgrade!
https://golang.org/dl/