{"record":{"id":"37e136cf20aa0061","repo":"golang/go","slug":"file-not-found","errorCode":null,"errorMessage":"file not found","messagePattern":"file not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":80,"sourceCode":"\tif islocalname(path) {\n\t\tif base.Flag.NoLocalImports {\n\t\t\treturn nil, errors.New(\"local imports disallowed\")\n\t\t}\n\n\t\tif base.Flag.Cfg.PackageFile != nil {\n\t\t\treturn os.Open(base.Flag.Cfg.PackageFile[path])\n\t\t}\n\n\t\t// try .a before .o.  important for building libraries:\n\t\t// if there is an array.o in the array.a library,\n\t\t// want to find all of array.a, not just array.o.\n\t\tif file, err := os.Open(fmt.Sprintf(\"%s.a\", path)); err == nil {\n\t\t\treturn file, nil\n\t\t}\n\t\tif file, err := os.Open(fmt.Sprintf(\"%s.o\", path)); err == nil {\n\t\t\treturn file, nil\n\t\t}\n\t\treturn nil, errors.New(\"file not found\")\n\t}\n\n\t// local imports should be canonicalized already.\n\t// don't want to see \"encoding/../encoding/base64\"\n\t// as different from \"encoding/base64\".\n\tif q := pathpkg.Clean(path); q != path {\n\t\treturn nil, fmt.Errorf(\"non-canonical import path %q (should be %q)\", path, q)\n\t}\n\n\tif base.Flag.Cfg.PackageFile != nil {\n\t\treturn os.Open(base.Flag.Cfg.PackageFile[path])\n\t}\n\n\tfor _, dir := range base.Flag.Cfg.ImportDirs {\n\t\tif file, err := os.Open(fmt.Sprintf(\"%s/%s.a\", dir, path)); err == nil {\n\t\t\treturn file, nil\n\t\t}\n\t\tif file, err := os.Open(fmt.Sprintf(\"%s/%s.o\", dir, path)); err == nil {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L62-L98","documentation":"Thrown by openPackage when a local import path's archive could not be found: PackageFile map is nil (no -packagefile overlay), and neither `<path>.a` nor `<path>.o` exists on disk. The compiler tries .a before .o so that a complete library archive is preferred over a lone object file.","triggerScenarios":"A source file imports a local path (./foo, ../bar) but the compiled archive/object file does not exist at the expected location relative to the compiler's working directory; PackageFile overlay is not configured.","commonSituations":"The imported local package was never compiled; the build was run from the wrong working directory; stale build artifacts were cleaned; the import path's case does not match the file system; missing -I/-o build coordination.","solutions":["Build the imported local package first so its .a/.o exists at the path the compiler searches.","Run the compiler from the directory it expects (the source root), since local paths resolve relative to the compiler CWD.","Use the -packagefile overlay or -I import search flags if coordinating a custom build pipeline.","Switch to canonical module import paths to avoid CWD-relative resolution."],"exampleFix":"// before: relative local import, no artifact present\nimport \"./foo\"\n// after: build foo first, then depend on the produced archive\ngo build ./foo && go build .","handlingStrategy":"validation","validationCode":"// Confirm a local import target's archive exists before compiling.\nimport \"os\"\nfunc localArchiveExists(path string) bool {\n    for _, suf := range []string{\".a\", \".o\"} {\n        if _, err := os.Stat(path+suf); err == nil { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build dependencies in topological order so archives exist before dependents.","Run the compiler from the directory it expects for relative imports.","Prefer `go build` over raw `go tool compile` to get correct search coordination."],"tags":["compiler","imports","local-imports","missing-file","go-build"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}