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

TypeScript type exports are not working for modern environments #669

Open
spaguette opened this issue Jul 19, 2023 · 2 comments
Open

TypeScript type exports are not working for modern environments #669

spaguette opened this issue Jul 19, 2023 · 2 comments

Comments

@spaguette
Copy link

Hi!

Issue description

When importing anything from allotment, my tsc gives me the following error:

Could not find a declaration file for module 'allotment'. '<(Project path omitted)>/node_modules/allotment/dist/modern.mjs' implicitly has an 'any' type.
  There are types at '<(Project path omitted)>/node_modules/allotment/dist/types/src/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'allotment' library may need to update its package.json or typings.ts(7016)

Possible context

This seems to be related to the issue reported in TS: microsoft/TypeScript#52363

Environment

allotment 1.19.0
typescript 5.1.6
vite 4.4.4
NodeJS 18.13.0 (Mac M1)

I'm using "module": "esnext", "moduleResolution": "bundler", in my tsconfig. No other library so far has given the same error for me.

Possible workaround

While it is a hack, the workaround that worked for me so far was to create a typings file like the following:

declare module "allotment" {
  export * from "allotment/dist/types/src/index.d.ts";
}
@mark-dr
Copy link

mark-dr commented Jul 26, 2023

This tripped me up too. Thanks for the workaround!

For additional context/evidence, here's the arethetypeswrong page for the latest allotment version: https://arethetypeswrong.github.io/?p=allotment%401.19.2

@pangxiaoli
Copy link
Contributor

pangxiaoli commented Oct 16, 2023

Hello,
I encountered this issue in version 1.19.3 on vite

could you please add the following content to package.json 'exports':

{
  "exports": {
    ".": {
      "require": "./dist/modern.mjs",
      "import": "./dist/module.js",
      "types": "./dist/types/src/index.d.ts"
    }
  },
}

here is doc for node about this fields:
https://nodejs.org/api/packages.html#packages_conditional_exports

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