Skip to content

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

Description

@stevecastaneda

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 typescript@7.0.2 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions