Hyperledger: Cannot compile chaincode, cannot find package error

+1 vote

Hi I am trying to running Hyperledger chain code on MAC. When I try to compile the code, 

cd $GOPATH/src/github.com/chaincode1
go build

i am getting error:

chaincode1.go:30:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of: /usr/local/Cellar/go/1.7.1/libexec/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT) ($GOPATH not set)
Oct 26, 2018 in Blockchain by digger
• 26,600 points
1,784 views

Please run the below command and tell what output you get:

$ echo $GOPATH
Hi @Tina. I am facing the same issue. I don't see any output when I run this command.

@Raj

Seems like GOPATH is not set. You have to set the GOPATH as follows:

Find where you have installed go lang. 

$ whereis go

Export using the following command:

export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin

4 answers to this question.

+2 votes
Best answer

As the error says, it cant find the source code on the local system. You have to have the source on your system. You can solve this error as follows:

$ cd $GOPATH/src/github.com
$ mkdir hyperledger
$ cd hyperledger
$ git clone http://gerrit.hyperledger.org/r/fabric.git
answered Oct 26, 2018 by Omkar
• 68,480 points

selected May 6 by digger
+1 vote

You will need to get following go libraries to compile chaincode locally.

go get github.com/hyperledger/fabric/protos/peer
go get github.com/hyperledger/fabric/core/chaincode/shim

These libraries will be installed under GOPATH, make sure it is set.

In case if you get any(specific to context and plugin) errors for "go get" command , then follow the procedure mentioned below to resolve.

Upgrade to latest version of GO.

sudo apt-get purge golang*

sudo rm -rf /usr/lib/go-1.6/ /usr/lib/go-1.6/src/ /usr/lib/go-1.6/src/runtime/ /usr/lib/go-1.6/src/runtime/race

curl -O https://storage.googleapis.com/golang/go1.11.1.linux-amd64.tar.gz

sudo tar -C /usr/local -xzf go1.11.1.linux-amd64.tar.gz

mkdir -p ~/go; echo "export GOPATH=$HOME/go" >> ~/.bashrc

echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc

source ~/.bashrc

Then

go get github.com/hyperledger/fabric/core/chaincode/shim
go get github.com/hyperledger/fabric/protos/peer
answered Mar 30 by Shahid Hussain
+1 vote

Follow the process:

$ mkdir -p $GOPATH/src/github.com/hyperledger
$ cd $GOPATH/src/github.com/hyperledger
$ git clone -b release-1.2 https://github.com/hyperledger/fabric.git
answered Apr 24 by Pavan
Hi @Pavan. Tried this, still getting the same error. Any other way to solve this?
0 votes
I had the same problem. I solved it by setting gopath location for go projects. Then when I ran the commands, this error was gone.
answered May 6 by Komal

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
4 answers

Hyperledger fabric: enrollAdmin.js Error: Cannot find module 'fabric-client'

Change your directory to fabric-samples/fabrcar. And run: npm ...READ MORE

answered Nov 21, 2018 in Blockchain by Omkar
• 68,480 points
1,364 views