microsoft / microsoft/TypeScript
Mechanism to specify input source location to find `package.json` instead of output source location when determining module format
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
nodenext, ts2351, construct
### 🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "A default import of a commonjs module with a default in a esm file doesn't seem to be the default export of that module when module is node16 or nodenext".
### ⏯ Playground Link
N/A
### 💻 Code
```
git clone https://github.com/monsanto/typescript-nodenext-bug
cd typescript-nodenext-bug
npm install
npm run tsc
```
### 🙁 Actual behavior
```
foo/index.ts:6:5 - error TS2351: This expression is not constructable.
Type 'typeof import("/typescript-nodenext-bug/.cache/foolib/class")' has no construct signatures.
6 new CBad();
~~~~
Found 1 error.
```
### 🙂 Expected behavior
It succeeds.
### Additional information about the issue
- This issue requires a composite project, `NodeNext`, a package boundary, a default export, and a parent directory with a file package.{json, json5, yaml} without `type`: `module`.
- Please note that import default inside `foo`'s package boundary works.
- One can delete the provided package.json after installing and run `node_modules/typescript/bin/tsc --build tsconfig-base.json` to test without `package.json` present.
- One can see other package extensions trigger the bug by `mv package.json package.yaml` and `pnpm run tsc`.
- This is not a CommonJS project. It doesn't matter that there is a parent `package.json` without it. Node doesn't even read `package.yaml`.
- This is from a real-world monorepo where there is a root pnpm `package.json5` for cross-package scripts.
Cross-ref for #62200
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 typescript-nodenext-bug 复现开始:运行 npm install 和 npm run tsc,然后检查 tsconfig-base.json 以及 issue 中描述的 package.json、package.json5 和 package.yaml 变体。比较父 package 元数据存在和不存在时的 NodeNext 模块格式结果;当复现能够在没有 TS2351 的情况下成功时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- node.js, typescript
- 领域
- build-system, compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100