cjs-wrapper.d.ts drops all named exports and the Nylas class type under exports-map resolution
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
从 cjs-wrapper.d.ts、exports map 和 lib/types/nylas.d.ts 开始,比较 CommonJS 和 ESM 的类型入口点。使用 node16 和 bundler 解析运行提供的 t.ts 和 tsconfig.json,同时关闭 skipLibCheck;当 CommonJS 使用者能够保留具名 exports 和 Nylas 类类型且没有声明错误时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
cjs-wrapper.d.ts uses export =, so the export * from './lib/types/models/index.js' line above it has no effect. Any TypeScript config that resolves through the exports map with the require condition (moduleResolution node16, nodenext, or bundler with module: commonjs) loses every named export: NylasApiError, NylasSdkTimeoutError, NylasOAuthError, and all the model types. The default import also stops working as a type, because export = nylasExport where nylasExport is typeof Nylas exposes the constructor value, not the class.
The runtime wrapper is fine. require('nylas') does expose the error classes via the Object.assign. Only the typings are wrong.
This was masked under moduleResolution: node10, which ignores exports and reads the top-level types field (lib/types/nylas.d.ts). TypeScript 7 removed node10, so every CommonJS consumer hits this on upgrade.
To Reproduce
// t.ts
import Nylas, { NylasApiError, NylasSdkTimeoutError } from "nylas";
let client: Nylas | undefined;
{
"compilerOptions": {
"module": "node16",
"moduleResolution": "node16",
"target": "es2022",
"types": ["node"],
"skipLibCheck": true,
"noEmit": true
},
"files": ["t.ts"]
}
$ npx -p [email protected] tsc -p tsconfig.json
t.ts(1,17): error TS2305: Module '"nylas"' has no exported member 'NylasApiError'.
t.ts(1,32): error TS2305: Module '"nylas"' has no exported member 'NylasSdkTimeoutError'.
t.ts(2,13): error TS2749: 'Nylas' refers to a value, but is being used as a type here. Did you mean 'typeof Nylas'?
Same result with moduleResolution: bundler + module: commonjs. Same result on TypeScript 5.9.3 with node16. Passes on 5.9.3 with moduleResolution: node10.
With skipLibCheck off, the wrapper itself reports TS2309: An export assignment cannot be used in a module with other exported elements, which is the root cause.
Expected behavior
CommonJS consumers get the same named exports and the same Nylas class type as ESM consumers.
One way to do it: keep export = but merge the named exports into it with a namespace, so the wrapper stays require-compatible and the names come back:
import NylasClass from './lib/types/nylas.js';
import * as models from './lib/types/models/index.js';
declare const nylasExport: typeof NylasClass & typeof models;
export = nylasExport;
plus a declare namespace or type Nylas = NylasClass so the default import works as a type. Happy to open a PR if you want one.
SDK Version:
8.4.0 (also present on main as of today)
Additional context
Node 22, TypeScript 7.0.2 and 5.9.3.
- 主要语言
- TypeScript
- 星标
- 180
- 派生
- 126
- 平均合并
- 4 天 6 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nylas/nylas-nodejs 的其他 Issue
-
Response body read errors bypass the SDK's typed error handling可能重新可做 @radenkovic 于 84 天前认领,目前没有进行中的 PR。 未关闭
nylas/nylas-nodejs#757 · 已指派 1 人 ·
-
bug
难度 2/5 1-3 小时 新手友好度 45/100
nylas/nylas-nodejs#755 ·
-
mock mode support可能重新可做 @AaronDDM 于 405 天前认领,目前没有进行中的 PR。 未关闭enhancement
nylas/nylas-nodejs#462 · 1 条评论 · 1 个 reaction · 已指派 1 人 ·
查看 nylas/nylas-nodejs 的全部 Issue
相似的 Issue
-
area:editor bug issue-form:bug P0 platform:windows review: low
难度 2/5 1-3 小时 新手友好度 64/100
1lck/Lithe-IDEA#1388 ·
维护者通常 1 天内回复
-
fix(api): isToolAuditEnabled swallows database read errors on auditToolOperations without logging未关闭area: backend bug priority: low
难度 2/5 1-3 小时 新手友好度 82/100
snapotter-hq/SnapOtter#3238 ·
维护者通常 1 天内回复
-
rig up --plan times out after 5 s and reports an UNKNOWN outcome while the daemon completes the plan未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/servers#5216 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复