nylas / nylas/nylas-nodejs

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

Open
#760 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
181
Forks
126
Avg merge
1d 20h
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cjs-wrapper.d.ts, the exports map, and lib/types/nylas.d.ts to compare the CommonJS and ESM type entry points. Run the provided t.ts and tsconfig.json with node16 and bundler resolution, including skipLibCheck off; done means CommonJS consumers retain the named exports and Nylas class type without declaration errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.