Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

CJS vs ESM import issue?

未关闭
#2,914 0 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
领域
backend, cloud

调研方向

首先,在使用 ESM、Node.js 20.13.1、firebase-admin 12.5.0 以及所示 Node16 tsconfig 的 Firebase Cloud Functions TypeScript 项目中复现报告的赋值错误。比较 @google-cloud/storage 的 CJS 和 ESM File 类型,以及 issue 中链接的讨论;当原因和适当的项目级解决方案确定后,即表示完成。

由索引模型根据 Issue 内容生成。

描述

api: storage
[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment
  • Operating System version: MacOS 15.4.1
  • Firebase SDK version: firebase-admin 12.5.0
  • Firebase Product: storage
  • Node.js version: 20.13.1
  • NPM version: 10.8.0
[REQUIRED] Step 3: Describe the problem

Basically what happened here. It's just there has been no answer to that, only workaround, so I post it here.

Happened to me when importing:

import type { File } from "@google-cloud/storage";

It says:

TS2322: Type
import("/WebstormProjects/firebase/functions/node_modules/@google-cloud/storage/build/cjs/src/file").File
is not assignable to type
import("/WebstormProjects/firebase/functions/node_modules/@google-cloud/storage/build/esm/src/file", { with: { "resolution-mode": "import" } }).File
Property #private in type File refers to a different member that cannot be accessed from within type File
Steps to reproduce:

Create Firebase Cloud Functions project using typescript and ESM.

Relevant Code:

tsconfig:

    "module": "Node16",
    "moduleResolution": "Node16",
    "target": "es2020",
主要语言
TypeScript
星标
1.7k
派生
419
平均合并
4 天 20 小时
30 天内合并 PR
16

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/firebase-admin-node 的其他 Issue

查看 firebase/firebase-admin-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。