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

Add exports.types to package.json #26

Merged
merged 3 commits into from
May 2, 2024
Merged

Conversation

yuhgto
Copy link
Contributor

@yuhgto yuhgto commented Sep 8, 2023

Added the types file path to exports.types in package.json to prevent the following error:

Could not find a declaration file for module '@mondaycom/apps-sdk'. '/Users/diprobhowmik/Documents/Development/monday-code-demo/next-js-typescript-test/node_modules/@mondaycom/apps-sdk/dist/esm/index.js' implicitly has an 'any' type.
  There are types at '/Users/diprobhowmik/Documents/Development/monday-code-demo/next-js-typescript-test/node_modules/@mondaycom/apps-sdk/dist/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@mondaycom/apps-sdk' library may need to update its package.json or typings.

The reason behind this error is that node will ignore the types field if the package has an exports field. And since the exports didn't include an exports.types, node would not be able to find the relevant types .

Docs & stackoverflow here –
https://stackoverflow.com/a/76212193
https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing

Added the types file path to `exports.types` in package.json to prevent the following error: 
```
Could not find a declaration file for module '@mondaycom/apps-sdk'. '/Users/diprobhowmik/Documents/Development/monday-code-demo/next-js-typescript-test/node_modules/@mondaycom/apps-sdk/dist/esm/index.js' implicitly has an 'any' type.
  There are types at '/Users/diprobhowmik/Documents/Development/monday-code-demo/next-js-typescript-test/node_modules/@mondaycom/apps-sdk/dist/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@mondaycom/apps-sdk' library may need to update its package.json or typings.
```

The reason behind this error is that node will ignore the `types` field if the package has an `exports` field. And since the `exports` didn't include an `exports.types`, node would not be able to find the relevant types .
@yuhgto
Copy link
Contributor Author

yuhgto commented Dec 21, 2023

closing because its stale

@yuhgto yuhgto closed this Dec 21, 2023
@yuhgto
Copy link
Contributor Author

yuhgto commented Apr 12, 2024

Hey, reopening this because someone brought it up again in the dev community.

We are using an outdated package.json structure: as of Typescript 4.7, the types field in package.json will no longer be used. We need to move the types field under exports

See this StackOverflow - https://stackoverflow.com/questions/76211877/the-xxxx-library-may-need-to-update-its-package-json-or-typings-ts/76212193#76212193

@yuhgto yuhgto reopened this Apr 12, 2024
Copy link
Collaborator

@DorShakedMonday DorShakedMonday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the stackoverflow link you have provided, the types should be first inorder.
This sounds like a myth, but won't hurt to make it first in the declaration order

@yuhgto yuhgto merged commit 3a38282 into master May 2, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants