Package io/fs: unrecognized import path “io/fs”: import path does not begin with hostname

        
            package main
            
            import (
            	"fmt"
            	myio "io/fs"
            )
            
            func main() {
            	fmt.Println("Hello, World!")
            }
        
    

The error “unrecognized import path ‘io/fs’: import path does not begin with hostname” occurs when you try to import a package using the new package path style introduced in Go 1.16. With this new style, the package paths must begin with a hostname followed by a slash.

In the example above, we are importing the “io/fs” package, but the import path does not follow the new style. To fix this error, you can add a custom name for the imported package using the “import” statement, as shown in the code example.

We import the “io/fs” package with the alias “myio”. Using this alias, we can then reference the package in our code.

By using a custom name for the imported package, we can avoid the error and still use the necessary functionality provided by the “io/fs” package.

Leave a comment