nodejs / nodejs/node

Allow type stripping in pnpm deploy monorepos

Offen
#61,793 10 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature request
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

What is the problem this feature will solve?

node.js supports running a subset of typescript nativly, but for reasons doesn't allow this feature for files in node_modules.

A positive caveat is that node wants to support npm workspaces, where local sub packages are required thru node_modules. To do so it checks the real path of the file, and will type strip it if it's not within node_modules.

This also works in pnpm workspaces, but breaks in pnpm deploy. This repo demonstrates that behavior.

Read or run repro.sh steps to reproduce.

This difference between workspace and deploy structure

bin/node_modules/lib -> ../../lib
out/node_modules/lib -> .pnpm/lib@file++++lib/node_modules/lib

cause this error in out/index.ts, but not bin/index.ts

Error [ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING]: Stripping types is currently unsupported for files under node_modules, for "file:///out/node_modules/.pnpm/lib@file++++lib/node_modules/lib/index.ts"

This would also break in npm, pnpm and other dependency managers that use install-links or other steps that indirect the workspace dependencies into node_modules.

What is the feature you are proposing to solve the problem?

Either remove the node_modules restriction, add more detection's for 'local node_modules' cases - such as private: true or a new marker, or establish export conditions for type stripping.

I am okay with emitting .js and using it in my deployed app, but I want to use .ts in development, and I don't want dev tools to require possibly stale .js files.

I think a reasonable solution is an export condition for 'type stripping not supported' that node would use to fallback to .js instead of erroring.

"exports": {
  "unsupportedTypeStripping": "out/index.js",
  "default": "src/index.ts",
}
What alternatives have you considered?

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führe repro.sh aus und vergleiche den erfolgreichen bin/index.ts-Fall mit dem fehlschlagenden out/index.ts-Fall, einschließlich ihrer node_modules-Pfade. Untersuche, wie der indirekte Workspace-Abhängigkeitspfad von pnpm deploy die Einschränkung für das Type-Stripping in node_modules auslöst; die Aufgabe ist abgeschlossen, wenn die bereitgestellte Anwendung die TypeScript-Workspace-Abhängigkeit ohne ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING verwenden kann, während die Entwicklung weiterhin .ts-Dateien verwenden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.