Skip to content

TypeScript Not Working When Package.json type is "module" #549

@Lozoute

Description

@Lozoute

Describe the bug
When installing Nylas SDK 7 to a new repo, using TypeScript 5 and type "module" in package.json, TypeScript throws the error This expression is not constructable. adding type: "module" into the package.json of Nylas fixes the problem but then commonjs requires do not work anymore.

To Reproduce
1 Create a new repo

2 Add this package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "tsc && node nylas.mjs"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "nylas": "^7.2.1"
  },
  "devDependencies": {
    "typescript": "^5.4.2"
  }
}

3. Add this tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "declaration": true,
    "esModuleInterop": false,
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "strictFunctionTypes": false,
    "strictBindCallApply": false,
    "strictPropertyInitialization": false,
    "skipLibCheck": true,
    "resolvePackageJsonExports": true,
  },
  "exclude": ["modules/clients/**/*"]
}

4. Add this nylas.mts file

import Nylas from 'nylas';


const apiKey = 'YOUR_API_KEY';
const apiUri = 'https://api.eu.nylas.com';

const nylas = new Nylas({
  apiKey: apiKey,
  apiUri: apiUri
});


const result = await nylas.messages.list({
  identifier: "YOUR_GRANT",
  queryParams: {
    limit: 20,
  },
});

console.log(result);

5. npm install && npm start

Expected behavior
Well I guess we should have no error but the tsc compiler throws the error This expression is not constructable.

SDK Version:
7.2.1

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions