{"record":{"id":"126e78e06b4f52e5","repo":"golang/go","slug":"import-path-contains-backslash-use-slash-q","errorCode":null,"errorMessage":"import path contains backslash; use slash: %q","messagePattern":"import path contains backslash; use slash: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":324,"sourceCode":"\n\tif strings.Contains(path, \"\\x00\") {\n\t\treturn errors.New(\"import path contains NUL\")\n\t}\n\n\tfor ri := range base.ReservedImports {\n\t\tif path == ri {\n\t\t\treturn fmt.Errorf(\"import path %q is reserved and cannot be used\", path)\n\t\t}\n\t}\n\n\tfor _, r := range path {\n\t\tswitch {\n\t\tcase r == utf8.RuneError:\n\t\t\treturn fmt.Errorf(\"import path contains invalid UTF-8 sequence: %q\", path)\n\t\tcase r < 0x20 || r == 0x7f:\n\t\t\treturn fmt.Errorf(\"import path contains control character: %q\", path)\n\t\tcase r == '\\\\':\n\t\t\treturn fmt.Errorf(\"import path contains backslash; use slash: %q\", path)\n\t\tcase !allowSpace && unicode.IsSpace(r):\n\t\t\treturn fmt.Errorf(\"import path contains space character: %q\", path)\n\t\tcase strings.ContainsRune(\"!\\\"#$%&'()*,:;<=>?[]^`{|}\", r):\n\t\t\treturn fmt.Errorf(\"import path contains invalid character '%c': %q\", r, path)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":306,"sourceCodeEnd":334,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L306-L334","documentation":"Returned by checkImportPath when a path rune is a backslash. Go import paths use forward slashes as separators (like URL paths) and forbid backslashes, which is especially important on Windows where backslash is a path separator.","triggerScenarios":"An import path like example\\\\foo or C:\\\\Users\\\\... containing '\\\\'; the switch case r == '\\\\' fires.","commonSituations":"Windows developers pasting filesystem paths into imports instead of module paths; tools generating paths with OS separators; mixing URL-style and Windows-style separators.","solutions":["Replace all backslashes with forward slashes in the import path.","Use the module path (example.com/foo) rather than an absolute filesystem path.","Run gofmt/goimports, which normalize import paths."],"exampleFix":"// before\n import \"example\\\\foo\"\n// after\n import \"example.com/foo\"","handlingStrategy":"validation","validationCode":"if strings.ContainsRune(path, '\\\\') {\n    return fmt.Errorf(\"use forward slashes in import path: %q\", path)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use module paths (example.com/foo), not OS filesystem paths.","On Windows, normalize backslashes to slashes before importing."],"tags":["go-compiler","import-path","windows","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}