
google identity services(gis)sdk 突然报错 `._$e`,通常源于 `renderbutton` 配置项 `width` 类型变更——从字符串强制改为数字类型,需将 `'200'` 改为 `200`,否则触发静默失败。
近期许多开发者反馈,在未修改代码的情况下,Google 登录按钮初始化突然失败,并在浏览器控制台出现类似 Uncaught TypeError: Cannot read properties of undefined (reading '_$e') 或直接指向
核心原因在于:Google 已悄然将 window.google.accounts.id.renderButton() 方法中 width 配置项的类型由 string(如 '300')严格改为 number(如 300)。即使传入合法数值字符串(如 '200'),SDK 内部也会因类型不匹配而中断渲染流程,最终抛出难以定位的 ._$e 错误——这是一个内部私有属性访问异常,本质是参数校验失败后的副作用。
✅ 正确写法(推荐):
const button = document.getElementById('g_id_onload');
window.google.accounts.id.renderButton(button, {
type: 'standard',
theme: 'outline',
size: 'large',
width: 200, // ← 必须为 number 类型,不可加引号
text: 'signin_with',
logo_alignment: 'left'
});❌ 错误写法(将立即触发 ._$e):
// 即使值正确,字符串类型也会导致失败
window.google.accounts.id.renderButton(button, {
width: '200' // ❌ 字符串 —— 不再被接受
});⚠️ 注意事项:
- width 是唯一已知被强制类型收紧的字段,但建议同步检查其他数值型配置(如 height,虽暂未报错,但未来可能跟进);
- Google 官方文档尚未更新(截至 2024 年仍显示 width: string),请以实际运行行为为准;
- 若使用 TypeScript,建议手动补充类型声明或通过 as const 显式约束:
renderButton(button, { width: 200 as number }); - 加载 SDK 后应校验 window.google?.accounts?.id 是否就绪,避免因异步加载未完成就调用 renderButton。
总结:这不是兼容性降级,而是 Google 向更健壮的类型安全演进的信号。将所有 width、潜在 height 等数值配置去引号化,即可快速恢复功能。建议将此检查纳入 CI 构建或代码审查清单,防范同类隐式类型变更带来的线上故障。










