{"record":{"id":"aff01b948d0c27c9","repo":"golang/go","slug":"disallowed-import-path-q","errorCode":null,"errorMessage":"disallowed import path %q","messagePattern":"disallowed import path %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":859,"sourceCode":"// the package path is malformed (for example, the path contains \"mod/\" or \"@\").\n//\n// loadPackageData returns a boolean, loaded, which is true if this is the\n// first time the package was loaded. Callers may preload imports in this case.\nfunc 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,","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L841-L877","documentation":"Import paths beginning with the literal prefix 'mod/' are explicitly disallowed by the Go toolchain. The 'mod/' prefix could cause accidental lookups inside the $GOPATH/pkg/mod/ module cache directory tree. Since this prefix does not begin with a domain name, it is owned by the Go core for potential standard library use, so it is blocked entirely to prevent ambiguity.","triggerScenarios":"Any import statement, package path, or go build target that starts with the string 'mod/'. For example: import \"mod/myproject\" or go build mod/something. The check fires at the very top of loadPackageData before any resolution is attempted.","commonSituations":"Choosing a module path that happens to start with 'mod/'. Copying example code that uses a hypothetical 'mod/' path. Automated code generators or scaffolding tools that produce import paths starting with 'mod/'. Abbreviating 'modules/' or 'module/' to 'mod/' in import paths.","solutions":["Rename the module or package so its import path does not start with 'mod/'. Use a domain-prefixed path.","If this is a standard library path you're trying to use, check the correct import name in Go documentation.","Update go.mod's module directive and all importers if the module path changes."],"exampleFix":"// before — reserved prefix\nimport \"mod/myproject\"\n// after — domain-prefixed path\nimport \"github.com/user/myproject\"","handlingStrategy":"validation","validationCode":"// Validate import paths against known disallowed prefixes.\nfunc validateImportPath(path string) error {\n    if strings.HasPrefix(path, \"mod/\") {\n        return fmt.Errorf(\"import path %q uses reserved prefix mod/\", path)\n    }\n    if strings.Contains(path, \"@\") {\n        return fmt.Errorf(\"import path %q contains @ — use go get/go install for path@version\", path)\n    }\n    return nil\n}","typeGuard":"// Check whether an import path is allowed by the Go toolchain.\nfunc isAllowedImportPath(path string) bool {\n    return path != \"\" &&\n        !strings.HasPrefix(path, \"mod/\") &&\n        !strings.Contains(path, \"@\")\n}","tryCatchPattern":null,"preventionTips":["Always prefix module paths with a domain (e.g., github.com/user/project).","Never use 'mod/' as an import path prefix — it is reserved by the Go core.","Add a CI lint check for import paths starting with reserved prefixes."],"tags":["go","go-build","import-path","modules","validation","reserved-prefix"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}