You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo应用调用Date构造函数报错:constructor is not callable

解决React Native Expo中new Date()报TypeError: constructor is not callable的问题

核心问题出在你安装的firebase-admin包上——这个是专门给Node.js后端使用的工具包,完全不能在React Native/Expo的前端环境中引入。它会污染全局运行环境,破坏原生的Date构造函数,才导致了这个报错。

解决步骤:

  • 先卸载firebase-admin:
    npm uninstall firebase-admin
    # 用yarn的话执行下面这句
    yarn remove firebase-admin
    
  • 如果需要在前端使用Firebase功能,换成前端专用的firebase包:
    npm install firebase
    # 用yarn的话执行下面这句
    yarn add firebase
    
    后续按照Firebase官方的前端SDK文档配置即可。

验证

卸载完成后重启Expo开发服务器,再运行你的代码,new Date()就能正常工作了——你的代码本身没有问题,原生Date在Expo和React Native中是完全支持的,就是这个后端包引发的环境冲突。

内容的提问来源于stack exchange,提问作者Mo Miah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:37:34