{
  "id": "go/self-import-cycle",
  "signature": "import cycle not allowed: package main imports itself",
  "signature_zh": "不允许导入循环：包 main 导入了自身",
  "regex": "import cycle not allowed: package .+ imports itself",
  "domain": "go",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "A package directly or indirectly imports itself, creating a dependency cycle that the Go compiler cannot resolve.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个包直接或间接地导入了自身，造成了 Go 编译器无法解决的依赖循环。",
  "versions": [
    {
      "version": "Go 1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Files in the same package cannot import the package; they share the same namespace.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Blank import still triggers the import mechanism and does not resolve the cycle.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Extract shared types or functions into a third package that both original packages import",
      "success_rate": 0.95,
      "how": "Extract shared types or functions into a third package that both original packages import",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use interfaces to invert dependencies: define an interface in one package and implement it in another",
      "success_rate": 0.9,
      "how": "Use interfaces to invert dependencies: define an interface in one package and implement it in another",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "将共享的类型或函数提取到第三个包中，让原始的两个包都导入该包",
    "使用接口反转依赖：在一个包中定义接口，在另一个包中实现它"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/doc/faq#cyclic_imports",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-02-28",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}