gopherjs / gopherjs.github.io

GopherJS Playground
https://gopherjs.github.io/playground/
23 stars 12 forks source link

Missing $copy function when building my playground. #38

Closed PeerXu closed 8 years ago

PeerXu commented 8 years ago

I try to build my own playground, but get the "panic: $copy is not defined" error message in output box. Steps:

  1. install gopherjs
  2. install gopherjs.github.io
  3. execute gopherjs.github.io/playground/update.sh
  4. execute gopherjs serve to start a server
  5. visit http://localhost:8080/github.com/gopherjs/gopherjs.github.io/playground/ and press Run button

But get the error message in output box.

And I found the missing function $copy is move to types.go file at https://github.com/gopherjs/gopherjs/commit/a90f6553c90f61ab018c32ecc0d0390baf760d8a

hope it is useful.

dmitshur commented 8 years ago

Thanks for reporting this.

What happens if you do all that but skip step 3?

The update.sh script is known to have issues/limitations and it's difficult to use. There's an open issue #36 to refactor it so that it works in more environments, without problems. That issue describes some of known limitations, so it might be helpful for you to look at it.

If it works when you skip step 3, then the real fix it to resolve #36.

PeerXu commented 8 years ago

I try to remove gopherjs and gopherjs.github.io package from $GOROOT and $GOPATH and redo steps without step 3. But get the same error message. After that, I write a compiler from playground.go. Get the same error message.

gopherjs run compiler.go > hello.js

compiler.go

dmitshur commented 8 years ago

I can reproduce. This is a valid issue (/cc @neelance), thank you for reporting @PeerXu.

It took me a while to figure out what was going on. I first tried the instructions for developing on GopherJS Playground at https://github.com/gopherjs/gopherjs.github.io/tree/master/playground#development, and everything worked fine for me, the playground was served and I could compile successfully in it.

Then I tried the compiler.go program you've posted above. I had to make some minor changes to it to clean its output, but I got it to output the generated JavaScript, and tried running that in a browser, and I got same problem as you:

image

I tried to diff the result I got above vs the result of doing gopherjs build prog.go with same prog.go input:

package main
import "fmt"
func main() {
        fmt.Println("hello, world!")
}

And the diff was very strange. The working output generated by gopherjs binary, on the left, looked normal. The program generated with your compiler.go had some similar parts, but also some significant differences/missing pieces, and the variables were 1-2 letter long rather than original names:

image

Then I realized. When I was doing gopherjs serve, it wasn't rebuilding the actual playground because I already had a previously generated version in my $GOPATH/pkg cache.

So I deleted all of my $GOPATH/pkg, and I could reproduce the error in the served playground:

image

dmitshur commented 8 years ago

I suspect the problem is caused by the recent change from old golang.org/x/tools/go/types and related importer/exporter packages to the new go/types, see https://github.com/gopherjs/gopherjs/pull/278.

The currently built packages in https://github.com/gopherjs/gopherjs.github.io/tree/master/playground/pkg directory are no longer valid when the playground is recompiled with the latest gopherjs.

We need to update all the .a.js files, I think that should fix it, but there my additional followup work required to get it to work. I hope we can try to tackle issue #36 at the same time, so that updating the playground is a much more seamless process, and we can do it more often than we currently do. /cc @neelance

PeerXu commented 8 years ago

In my experience, copy $copy function to hello.js is work for me, but still waiting for the solution. :)