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,740 points
12,651 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
• 69,220 points

selected May 6, 2019 by digger

I already did what you said but i am still getting the same error my go path  $home/work the fabric is cloned into

$home/work/src/github.com/hyperledger

the chaincode is in $home/work/fabric-sample/chaincode/sacc

i also have another chaincode in

$home/work/src/chain/mediuchaincode

i can not compile any  of them , when i try go get it give me this

package github.com/hyperledger/fabric/core/chaincode/shim: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:

/usr/local/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)

/home/shovon/work/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOPATH)

Hope this helps!

To know more, Enroll with Blockchain training online today.

Thank You!!

+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, 2019 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, 2019 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, 2019 by Komal

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,424 views
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
• 69,220 points
5,172 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP