nodejs / nodejs/node

Allow type stripping in pnpm deploy monorepos

オープン
#61,793 コメント 10 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

repro.sh を実行し、成功する bin/index.ts のケースと失敗する out/index.ts のケースを、それぞれの node_modules パスも含めて比較します。pnpm deploy の間接的な workspace 依存関係パスが、node_modules での型ストリッピング制限をどのように発生させるのかを調査します。デプロイされたアプリが ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING なしで TypeScript の workspace 依存関係を使用でき、開発時には引き続き .ts ファイルを使用できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。