`index.d.cts` makes CommonJS TypeScript projects using `module: node16` fail with TS1479
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 52/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- firebase, react, typescript
研究方向
Start by reading the build:types-cjs script and comparing dist/index.d.ts with dist/index.d.cts; the issue says the latter is copied from the former. Reproduce the TS1479 errors with module and moduleResolution set to node16 and skipLibCheck: false, then inspect the local declaration re-exports. Done means the CommonJS TypeScript project can type-check its reactfire import without those errors.
由索引模型根據 Issue 內容生成。
描述
A CommonJS TypeScript project that uses module: node16 and skipLibCheck: false cannot type-check an import of reactfire. I found this while reviewing #838, and it is already true on main.
What happens
tscreports TS1479 on every line ofnode_modules/reactfire/dist/index.d.ctsthat imports or re-exports a local file: "The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'."- I got 11 of these on
mainand 12 on #838's head, where the extra one is the new./utils.jsre-export. - With
skipLibCheck: truethe errors go away and the imported types still resolve correctly, so projects with that setting are not affected. - attw reports all four resolution modes green, so the CI "Verify package" job does not catch it.
Steps to reproduce
- Create a project with no
"type"field in itspackage.jsonand atsconfig.jsonwithmoduleandmoduleResolutionset tonode16,skipLibCheck: false. - Install
reactfire(I used a tarball packed frommainateb3376a),firebase13.1.0 and React 19. - Import
useUserfromreactfirein a.tsfile and runtsc.
Cause, as far as I can tell
- The
build:types-cjsscript copiesdist/index.d.tstodist/index.d.cts, so the two files are identical. - The
.d.ctsfile is treated as CommonJS, but it re-exports from./auth.jsand the other per-module declarations, which sit in a"type": "module"package and are therefore ESM.
I have not tried a fix. If emitting real CommonJS declarations is more than this is worth, documenting skipLibCheck: true for CommonJS projects may be enough.
- 主要語言
- TypeScript
- 星號
- 3.6k
- 分支
- 402
- 平均合併
- 2 天 3 小時
- 30 天內合併 PR
- 26
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
FirebaseExtended/reactfire 的其他 Issue
-
enhancement
難度 1/5 1-3 小時 新手友好度 64/100
FirebaseExtended/reactfire#851 · 1 則留言 ·
維護者通常 2 天內回覆
-
難度 5/5 一週以上 新手友好度 38/100
FirebaseExtended/reactfire#801 ·
維護者通常 2 天內回覆
-
v5
難度 4/5 3-5 天 新手友好度 48/100
FirebaseExtended/reactfire#793 ·
維護者通常 2 天內回覆
-
v5
難度 4/5 3-5 天 新手友好度 35/100
FirebaseExtended/reactfire#790 · 2 則留言 ·
維護者通常 2 天內回覆
-
v5
難度 4/5 3-5 天 新手友好度 55/100
FirebaseExtended/reactfire#789 ·
維護者通常 2 天內回覆
查看 FirebaseExtended/reactfire 的全部 Issue
相似的 Issue
-
bug needs-triage potential-regression
難度 2/5 1-3 小時 新手友好度 78/100
aws/aws-sdk-js-v3#8408 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
colinhacks/zod#6743 ·
維護者通常 1 天內回覆
-
[BUG] Packing list: the weight field drops digits on a slow connection and saves the wrong weight未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 79/100
openai/openai-node#3124 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 73/100
anthropics/anthropic-sdk-typescript#1296 ·
維護者通常 8 天內回覆