developer
developer

Reputation: 21

unrecognized import path "syscall/js"

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:

I am using go version go1.6.2 linux

Upvotes: 1

Views: 2767

Answers (2)

Philippe Matray
Philippe Matray

Reputation: 1521

There are some breaking changes in Go1.12 in syscall/js

The Callback type and NewCallback function have been renamed; they are now called Func and FuncOf, respectively. This is a breaking change, but WebAssembly support is still experimental and not yet subject to the Go 1 compatibility promise. Any code using the old names will need to be updated.

If a type implements the new Wrapper interface, ValueOf will use it to return the JavaScript value for that type.

The meaning of the zero Value has changed. It now represents the JavaScript undefined value instead of the number zero. This is a breaking change, but WebAssembly support is still experimental and not yet subject to the Go 1 compatibility promise. Any code relying on the zero Value to mean the number zero will need to be updated.

The new Value.Truthy method reports the JavaScript "truthiness" of a given value.


Here is a link to an example that uses React, Node and Go to get a clearer understanding.

https://github.com/phmatray/webassembly-demo

Upvotes: 2

peterSO
peterSO

Reputation: 166569

Go 1.11 Release Notes (August 2018)

WebAssembly

Go programs can call into JavaScript using the new experimental syscall/js package.


syscall/js was first introduced in Go1.11 (August 2018). Your output from the command go version is go1.6.2 l, an ancient (February 2016) and obsolete version.


After downloading a binary release of Go1.11 or later suitable for your system from Go Downloads, please follow the installation instructions, including the instructions for Uninstalling Go for your current version of Go.

Upvotes: 4

Related Questions