Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

cjs-wrapper.d.ts drops all named exports and the Nylas class type under exports-map resolution

Đang mở
#760 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
developer-experience

Hướng nghiên cứu

Bắt đầu với cjs-wrapper.d.ts, exports map và lib/types/nylas.d.ts để so sánh các entry point kiểu CommonJS và ESM. Chạy t.ts và tsconfig.json được cung cấp với cơ chế phân giải node16 và bundler, bao gồm cả khi tắt skipLibCheck; hoàn thành khi các consumer CommonJS vẫn giữ được các exports có tên và kiểu lớp Nylas mà không có lỗi khai báo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
180
Fork
126
Merge trung bình
4 ngày 6 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nylas/nylas-nodejs

Tất cả issue của nylas/nylas-nodejs

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.