Skip to content

Missing $copy function when building my playground. #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PeerXu opened this issue Jan 13, 2016 · 5 comments
Closed

Missing $copy function when building my playground. #38

PeerXu opened this issue Jan 13, 2016 · 5 comments

Comments

@PeerXu
Copy link

PeerXu commented Jan 13, 2016

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 gopherjs/gopherjs@a90f655

hope it is useful.

@dmitshur
Copy link
Member

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
Copy link
Author

PeerXu commented Jan 14, 2016

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
Copy link
Member

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
Copy link
Member

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 gopherjs/gopherjs#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
Copy link
Author

PeerXu commented Jan 15, 2016

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

dmitshur added a commit that referenced this issue Jan 17, 2016
This is the first update of playground after the GopherJS update of
go/types import paths and related changes.

Fixes #38.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants