lucide-react 升到 v1,Github 图标凭空消失了
给个人站的「GitHub / 邮箱」按钮补图标,顺手 import { Github, Mail } from "lucide-react"——Mail 好好的,Github 直接把构建干崩了。
现象
Export Github doesn't exist in target module
Did you mean to import Gift?
Mail等通用图标正常,唯独Github报「不存在」- 构建器(Turbopack/webpack)还热心提示「是不是想导入
Gift?」——按字符串距离瞎猜的,毫无语义 node_modules/.pnpm/lucide-react@1.17.0——版本停在 v1.x
Github、Gitlab、Twitter、Facebook、Linkedin、Youtube、Slack、Chrome、Figma…… 这些品牌商标图标在 lucide v1 被整体移除(商标不符合项目许可与范围),没有任何 drop-in 替代导出。GitBranch / GitFork 是无关的通用 git 动作图标,不是 GitHub 那只章鱼猫。通用 UI 图标(Mail / ArrowLeft / Search)不受影响。
根因
别信构建器的「Did you mean」——它做的是字符串近似匹配(Github → Gift),跟语义半毛钱关系没有。Github 是真的被删了,不是拼错。
下手前先问清楚库到底导出了什么:
node -e "const l=require('lucide-react'); const k=Object.keys(l); \
console.log('Mail:', k.includes('Mail')); \
console.log(k.filter(x=>/git|hub/i.test(x)))"
# Mail: true
# [ 'GitBranch', 'GitFork', ... ] ← 没有 Github正解
通用图标继续从 lucide 导(Mail 还在);品牌 mark 用一段内联 SVG 兜底,fill="currentColor" 让它跟随文字色:
import { Mail } from "lucide-react";
function GithubMark({ className }: { className?: string }) {
return (
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden className={className}>
<path d="M12 .5C5.37.5 0 5.78 0 12.29c0 5.2 3.44 9.6 8.21 11.16.6.11.82-.25.82-.57 0-.28-.01-1.02-.02-2-3.34.71-4.04-1.58-4.04-1.58-.55-1.36-1.33-1.73-1.33-1.73-1.09-.73.08-.71.08-.71 1.2.08 1.84 1.21 1.84 1.21 1.07 1.8 2.81 1.28 3.5.98.11-.76.42-1.28.76-1.57-2.67-.3-5.47-1.31-5.47-5.81 0-1.28.47-2.33 1.23-3.15-.12-.3-.53-1.5.12-3.14 0 0 1.01-.32 3.3 1.2a11.5 11.5 0 0 1 6.02 0c2.29-1.52 3.3-1.2 3.3-1.2.65 1.64.24 2.84.12 3.14.77.82 1.23 1.87 1.23 3.15 0 4.51-2.81 5.5-5.49 5.79.43.36.81 1.08.81 2.18 0 1.58-.01 2.85-.01 3.24 0 .32.21.69.83.57A12.04 12.04 0 0 0 24 12.29C24 5.78 18.63.5 12 .5Z" />
</svg>
);
}
const socialIcons = { github: GithubMark, mail: Mail } as const;也可以引 @icons-pack/react-simple-icons 或 react-icons/fa(FaGithub),但一个站就一两个品牌图标,内联 SVG 最省。
pnpm build 不再报 export 错误,章鱼猫正常渲染并跟随文字色。
一个连带的小坑
内联品牌 SVG 默认 vertical-align: baseline,紧贴文字会高低不齐。把图标 + 文字包进 inline-flex items-center gap-2 就居中对齐了——lucide 图标在不 flex 的容器里也会犯这毛病。
一句话外卖
lucide v1 删光了品牌 logo 图标,
Github不存在不是拼错;通用图标继续用 lucide,品牌 mark 用内联 SVG 兜底。