`index.d.cts` makes CommonJS TypeScript projects using `module: node16` fail with TS1479

Ouverte
#850 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
52/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
firebase, react, typescript

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug

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
  • tsc reports TS1479 on every line of node_modules/reactfire/dist/index.d.cts that 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 main and 12 on #838's head, where the extra one is the new ./utils.js re-export.
  • With skipLibCheck: true the 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 its package.json and a tsconfig.json with module and moduleResolution set to node16, skipLibCheck: false.
  • Install reactfire (I used a tarball packed from main at eb3376a), firebase 13.1.0 and React 19.
  • Import useUser from reactfire in a .ts file and run tsc.
Cause, as far as I can tell
  • The build:types-cjs script copies dist/index.d.ts to dist/index.d.cts, so the two files are identical.
  • The .d.cts file is treated as CommonJS, but it re-exports from ./auth.js and 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.

Langage dominant
TypeScript
Étoiles
3.6k
Forks
402
Merge moyen
2 j 3 h
PR mergées (30 j)
26

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de FirebaseExtended/reactfire

Toutes les issues de FirebaseExtended/reactfire

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.