Use of internal package not allowed

62.6k Views Asked by At

I'm trying to build and run a repo (https://github.com/hyperledger/fabric/tree/master) but this error keeps popping up and still I haven't found a solution to this.

consensus.go:12:2: use of internal package github.com/hyperledger/fabric/internal/pkg/identity not allowed

This is just one of many files that give this error. I'm pretty sure I'm doing something wrong since this repo is suppose to be working.

Go version :

go version go1.13.5 linux/amd64

OS : Linux Mint 19.2 Cinnamon

3

There are 3 best solutions below

2
On BEST ANSWER

Internal packages (packages that are inside a folder that has an internal folder in their path) can only be imported from packages rooted at the parent of the internal folder.

E.g. a package pkg/foo/internal/bar can be imported by the package pkg/foo/internal/baz and also from pkg/foo/baz, but cannot be imported by the package pkg nor can it be imported by pkg/bar. This is by design. This is so big, complex packages can be broken into smaller packages without having to expose internals.

You have to treat internal packages as "private" or non-existent from the "outside".

See related: Can I develop a go package in multiple source directories?

Read more about internal packages at Command go: Internal Directories.

Internal packages are a compiler restriction. If you want to expose them (if you want to use an internal package) in your own project, you have to remove the internal folder, and then of course you have to change the imports (import paths) too.

0
On
├── module1
│   ├── go.mod
│   ├── internal
│   │   └── pkga
│   ├── pkg1
│   └── pkg2
└── module2
    ├── go.mod
    └── pkg1

The internal/pkga package in module1 can be imported by the pkg1 and pkg2 packages in module1. But it cannot be imported by the pkg1 package of module2. The standard convention for internal packages: For packages with internal keywords in the export path, only the parent directory of internal and its child packages are allowed to be imported, and other packages cannot be imported. In the example given by the teacher, the parent directory of internal is module1, and the child packages of the parent directory are module1/pkg1 and module1/pkg2. Therefore, in this example, internal can only be imported from these three places. The above convention is verified by the Go compiler, and internal is a special directory name that the Go compiler can recognize when compiling the program. If the verification fails, an error will be reported.

1
On

Change fyne.io/fyne/v2/internal/widget To fyne.io/fyne/v2/widget

Just remove the /internal from the package path inside the code editor