Allow type stripping in pnpm deploy monorepos
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行 repro.sh,并比较成功的 bin/index.ts 情况与失败的 out/index.ts 情况,包括它们的 node_modules 路径。调查 pnpm deploy 的间接 workspace 依赖路径如何触发 node_modules 的类型剥离限制;完成的标准是,已部署的应用可以使用 TypeScript workspace 依赖而不会出现 ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING,同时开发过程仍可继续使用 .ts 文件。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100