go
naming
ai_generated
true
could not import — Go package in directory with hyphen causes import path mismatch
ID: go/hyphen-in-package-directory-name
85%Fix Rate
88%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Go package directory named with hyphens (my-package) creates a mismatch because Go package names cannot contain hyphens.
genericWorkarounds
-
95% success Rename directory to use underscores or no separator, match package declaration name
mv my-package mypackage # directory name should match or be importable as package name
-
82% success If external module, import by module path and alias the package name
import mypackage "github.com/org/my-package/subpkg" // alias resolves the hyphen
Dead Ends
Common approaches that don't work:
-
Use the directory name as-is in package declaration
90% fail
Go compiler rejects hyphens in package names; package mypackage in dir my-package causes import confusion
-
Use replace directive to map hyphenated path
80% fail
Replace directive remaps modules, not individual packages within a module; does not fix the naming issue