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

VSCode部署Firebase云函数时params.d.ts文件出现25个错误

解决Firebase云函数params.d.ts文件TypeScript编译错误

在使用TypeScript部署Firebase云函数时,node_modules/firebase-functions/lib/common/params.d.ts文件突然出现25个编译错误,未修改过该文件,此前部署正常,推测是依赖更新导致。更新TypeScript后问题仍存在,错误示例如下:

node_modules/firebase-functions/lib/common/params.d.ts:6:125 - error
TS1110: Type expected.

6 export declare type Split<S extends string, D extends string> = string extends S ? string[] : S extends "" ? [] : S extends ${D}${infer Tail} ? [...Split<Tail, D>] : S extends ${infer Head}${D}${infer Tail} ? string extends Head ? [...Split<Tail, D>] : [Head, ...Split<Tail, D>] : [

node_modules/firebase-functions/lib/common/params.d.ts:21:66 - error
TS1005: ';' expected.

21 export declare type Extract = Part extends `${infer Param}=**` ? Param : Part extends `${infer Param}=*` ? Param : Part extends `${infer Param}` ? Param : never;
~

node_modules/firebase-functions/lib/common/params.d.ts:33:1 - error
TS1160: Unterminated template literal. 33

以下是可行的解决方案:

  • 锁定firebase-functions到兼容版本
    最新版firebase-functions可能使用了当前TypeScript版本不支持的高级类型语法,可降级到已知兼容的稳定版本:

    npm install firebase-functions@3.24.1 --save
    # yarn用户执行:yarn add firebase-functions@3.24.1
    

    之后清理依赖缓存并重新安装:

    rm -rf node_modules package-lock.json
    npm install
    
  • 调整tsconfig.json配置
    确保TypeScript配置支持所需语法,或临时跳过库文件类型检查:

    {
      "compilerOptions": {
        "target": "ES2020",
        "lib": ["ES2020"],
        "skipLibCheck": true, // 绕过第三方库的类型检查,紧急场景可用
        "strict": true,
        "esModuleInterop": true
      }
    }
    
  • 同步更新所有Firebase依赖
    依赖版本不匹配可能引发冲突,同步更新所有Firebase相关包:

    npm install firebase-functions@latest firebase-admin@latest firebase-tools@latest --save
    
  • 清理缓存并重启TypeScript服务

    1. 打开VSCode命令面板(Ctrl+Shift+P),执行TypeScript: Restart TS Server
    2. 清理项目构建缓存并重新构建:
    rm -rf dist build
    npm run build
    

内容的提问来源于stack exchange,提问作者Chris Davenport

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 02:20:49