Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access API types when using ESM #418

Open
G-Rath opened this issue Jul 8, 2023 · 2 comments
Open

Cannot access API types when using ESM #418

G-Rath opened this issue Jul 8, 2023 · 2 comments

Comments

@G-Rath
Copy link

G-Rath commented Jul 8, 2023

Report bugs here only for the Node JavaScript library.

If you're having problems using Notion's API, or have any other feedback about the API including feature requests for the JavaScript library, please email support at [email protected].

Describe the bug
When using ESM TypeScript cannot import API types because api-endpoints is not exported according to ESM semantics.

To Reproduce
Node version: 18.16.0
Notion JS library version: 2.2.6

Steps to reproduce the behavior:

  1. Use latest TypeScript with tsconfig.json extending @tsconfig/node18, along with notion-sdk-js (i.e. npm i notion-sdk-js typescript @tsconfig/node18)
  2. Create a new index.mts file
  3. Attempt to import a type from @notionhq/client/build/src/api-endpoints

Expected behavior
The import to be error-free

Screenshots
image

Additional context

I'm pretty sure you could fix this by adding the following to the package.json:

  "exports": {
    ".": {
      "types": "./build/src/index.d.ts",
      "default": "./build/src/index.js"
    },
    "./build/src/api-endpoints": {
      "types": "./build/src/api-endpoints.d.ts"
    }
  },

This works locally, but I'm not experienced with ESM enough to say for sure that that is exactly what this package should be configured with, or if there's something missing which my use of the library doesn't hit.

The alternative that I know will work would be to re-export all of the types from index.d.ts with an alias:

export * as API from './api-endpoints'

That would allow import { API } from '@notionhq/client' which could then be used to access the types.

I'm happy to do a PR for either of these options (or both)

@kevinxh
Copy link

kevinxh commented Nov 9, 2023

YES! no types for those of us who use ESM... :(

@valeriivolkovskyi
Copy link

any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants