{"record":{"id":"b8f96576c0e82c42","repo":"golang/go","slug":"can-only-use-path-version-syntax-with-go-get-and","errorCode":null,"errorMessage":"can only use path@version syntax with 'go get' and 'go install' in module-aware mode","messagePattern":"can only use path@version syntax with 'go get' and 'go install' in module-aware mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":863,"sourceCode":"func loadPackageData(ld *modload.Loader, ctx context.Context, path, parentPath, parentDir, parentRoot string, parentIsStd bool, mode int) (bp *build.Package, loaded bool, err error) {\n\tctx, span := trace.StartSpan(ctx, \"load.loadPackageData \"+path)\n\tdefer span.Done()\n\n\tif path == \"\" {\n\t\tpanic(\"loadPackageData called with empty package path\")\n\t}\n\n\tif strings.HasPrefix(path, \"mod/\") {\n\t\t// Paths beginning with \"mod/\" might accidentally\n\t\t// look in the module cache directory tree in $GOPATH/pkg/mod/.\n\t\t// This prefix is owned by the Go core for possible use in the\n\t\t// standard library (since it does not begin with a domain name),\n\t\t// so it's OK to disallow entirely.\n\t\treturn nil, false, fmt.Errorf(\"disallowed import path %q\", path)\n\t}\n\n\tif strings.Contains(path, \"@\") {\n\t\treturn nil, false, errors.New(\"can only use path@version syntax with 'go get' and 'go install' in module-aware mode\")\n\t}\n\n\t// Determine canonical package path and directory.\n\t// For a local import the identifier is the pseudo-import path\n\t// we create from the full directory to the package.\n\t// Otherwise it is the usual import path.\n\t// For vendored imports, it is the expanded form.\n\t//\n\t// Note that when modules are enabled, local import paths are normally\n\t// canonicalized by modload.LoadPackages before now. However, if there's an\n\t// error resolving a local path, it will be returned untransformed\n\t// so that 'go list -e' reports something useful.\n\timportKey := importSpec{\n\t\tpath:        path,\n\t\tparentPath:  parentPath,\n\t\tparentDir:   parentDir,\n\t\tparentRoot:  parentRoot,\n\t\tparentIsStd: parentIsStd,","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L845-L881","documentation":"An import path or package argument containing an @ symbol (version qualifier, e.g., foo@v1.2.3) was used in a context that doesn't support it. The @version syntax is only valid with go get and go install in module-aware mode. Using it in other commands (go build, go run, go test) or in GOPATH mode triggers this error. The check fires during package loading when strings.Contains(path, '@') is true.","triggerScenarios":"Package loading in load/pkg.go encounters strings.Contains(path, '@') == true during import path resolution. This happens when a package argument or import path contains @ but the current command is not go get/go install, or when GO111MODULE=off (GOPATH mode) is active.","commonSituations":"Running go build or go run with a package@version argument (e.g., 'go build foo@v1.2.3'); using @version syntax in an import statement in source code; running in GOPATH mode (GO111MODULE=off) where version qualifiers aren't supported; using @version with go list or other commands that don't support it; misunderstanding module-mode semantics.","solutions":["Use go get or go install for version-qualified packages: 'go install foo@v1.2.3' instead of 'go build foo@v1.2.3'","If you need a specific version for building, run 'go get foo@v1.2.3' first to update go.mod, then 'go build ./...'","Ensure GO111MODULE is not set to off — use 'on' or 'auto' (the default in modern Go)","Remove any @version syntax from import paths in source code — version pinning belongs in go.mod, not in import statements"],"exampleFix":"// before: using @version with wrong command\n// $ go build golang.org/x/tools/cmd/goimports@latest\n// # error: can only use path@version syntax with go get and go install\n\n// after: use go install for version-qualified packages\n// $ go install golang.org/x/tools/cmd/goimports@latest\n\n// or for building local code with a specific dependency version:\n// $ go get golang.org/x/text@v0.14.0\n// $ go build ./...","handlingStrategy":"validation","validationCode":"// Validate that import paths and package arguments don't use @version\n// in contexts that don't support it.\nfunc validatePackageArg(path string, command string, moduleMode bool) error {\n    if strings.Contains(path, \"@\") {\n        if !moduleMode {\n            return fmt.Errorf(\"path@version requires module mode (GO111MODULE=on)\")\n        }\n        if command != \"get\" && command != \"install\" {\n            return fmt.Errorf(\"path@version only supported with go get and go install\")\n        }\n    }\n    return nil\n}\n\n// Check if module mode is active:\nfunc isModuleMode() bool {\n    mode := os.Getenv(\"GO111MODULE\")\n    return mode != \"off\" // \"on\", \"auto\", or empty all enable modules in modern Go\n}","typeGuard":"// This is a package loading error, returned as a plain error.\n// Detect by message:\nfunc isAtVersionError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"path@version syntax\")\n}","tryCatchPattern":"// For tooling that loads packages:\n// pkgs, err := packages.Load(cfg, pattern)\n// if err != nil {\n//     if isAtVersionError(err) {\n//         // User passed foo@version with an unsupported command.\n//         // Strip the version or suggest go get/go install.\n//         base := path[:strings.Index(path, \"@\")]\n//         fmt.Printf(\"Use 'go get %s' to fetch the version, then rebuild\\n\", pattern)\n//         fmt.Printf(\"Or use 'go install %s'\\n\", pattern)\n//     }\n// }","preventionTips":["Use go get or go install for version-qualified packages, not go build or go run","Ensure GO111MODULE is set to 'on' or 'auto' (default) for module support","Never put @version in source code import statements — version pinning goes in go.mod","For building tools at a specific version, use: go install golang.org/x/tools/cmd/foo@v1.0.0","For building local code with a specific dependency, run go get dep@version first, then go build ./...","Check GO111MODULE with 'go env GO111MODULE' if module mode seems inactive"],"tags":["go","modules","packages","versioning","gopath"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}