Error: package io/fs is not in goroot
This error message typically occurs when the Go compiler cannot find the io/fs
package in the GOROOT
directory. The io/fs
package was introduced in Go 1.16, so if you are using an older version of Go, this package may not be available.
To resolve this issue, you have a few options:
-
Upgrade Go version:
If you are using an older version of Go, consider upgrading to the latest stable version. You can download and install the latest version from the official Go website (https://golang.org/dl/). After upgrading, make sure to update yourPATH
environment variable to point to the new installation location. -
Check GOROOT:
Verify that yourGOROOT
environment variable is correctly set. TheGOROOT
variable should point to the directory where the Go standard library is located. You can check the value ofGOROOT
by running the commandgo env GOROOT
in your terminal or command prompt. -
Import with go.mod:
If you are already using a newer version of Go and have ago.mod
file in your project, make sure that the required version of theio/fs
package is specified in thego.mod
file. Use thego get
command to add the package to your module:go get -u io/fs
Example:
package main
import (
"fmt"
"io/fs"
)
func main() {
fs.WalkDir()
fmt.Println("Hello, world!")
}