Package io/fs is not in goroot

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:

  1. 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 your PATH environment variable to point to the new installation location.
  2. Check GOROOT:
    Verify that your GOROOT environment variable is correctly set. The GOROOT variable should point to the directory where the Go standard library is located. You can check the value of GOROOT by running the command go env GOROOT in your terminal or command prompt.
  3. Import with go.mod:
    If you are already using a newer version of Go and have a go.mod file in your project, make sure that the required version of the io/fs package is specified in the go.mod file. Use the go 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!")
  }
  

Same cateogry post

Leave a comment