smacker / go-tree-sitter

Golang bindings for tree-sitter https://github.com/tree-sitter/tree-sitter
MIT License
439 stars 123 forks source link

go mod error #115

Open rew1nter opened 1 year ago

rew1nter commented 1 year ago

This is the error Im getting upon running go mod tidy:

go: found github.com/smacker/go-tree-sitter/javascript in github.com/smacker/go-tree-sitter/javascript v0.0.1
xd imports
        github.com/smacker/go-tree-sitter/javascript: ambiguous import: found package github.com/smacker/go-tree-sitter/javascript in multiple modules:
        github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 (/drive/go/pkg/mod/github.com/smacker/go-tree-sitter@v0.0.0-20230720070738-0d0a9f78d8f8/javascript)
        github.com/smacker/go-tree-sitter/javascript v0.0.1 (/drive/go/pkg/mod/github.com/smacker/go-tree-sitter/javascript@v0.0.1)
natb1 commented 8 months ago

I had to pin the first option in the go.mod (add the line github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 in your example). This might be common go knowledge but I hadn't run into it before either.

rubencaro commented 5 months ago

I get the same error:

github.com/smacker/go-tree-sitter/javascript: ambiguous import: found package github.com/smacker/go-tree-sitter/javascript in multiple modules:
github.com/smacker/go-tree-sitter v0.0.0-20240514083259-c5d1f3f5f99e (/home/ruben/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/smacker/go-tree-sitter@v0.0.0-20240514083259-c5d1f3f5f99e/javascript)
github.com/smacker/go-tree-sitter/javascript v0.0.1 (/home/ruben/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/smacker/go-tree-sitter/javascript@v0.0.1)

The problem is that a module for the javascript parser for version 0.0.1 exists in the proxy service (see here https://pkg.go.dev/github.com/smacker/go-tree-sitter/javascript), so go mod tidy will see that one too. The source for that module is not there anymore (now it's just a package), but it looks like it was there at some point, and it is still cached in the proxy.

A workaround is just to deactivate the proxy and go directly to the source (github in this case):

$ GOPROXY=direct go mod tidy
go: finding module for package github.com/smacker/go-tree-sitter/javascript
go: finding module for package github.com/smacker/go-tree-sitter
go: found github.com/smacker/go-tree-sitter in github.com/smacker/go-tree-sitter v0.0.0-20240514083259-c5d1f3f5f99e
go: found github.com/smacker/go-tree-sitter/javascript in github.com/smacker/go-tree-sitter v0.0.0-20240514083259-c5d1f3f5f99e

@smacker do you know the way to get that module out of the proxy? It will be there annoying forever...