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 can't find the type declarations when importing as ESM #32

Open
mltsy opened this issue Feb 12, 2025 · 0 comments
Open

Typescript can't find the type declarations when importing as ESM #32

mltsy opened this issue Feb 12, 2025 · 0 comments

Comments

@mltsy
Copy link

mltsy commented Feb 12, 2025

using import { storageFactory } from "storage-factory";, Typescript gives me this error:

Could not find a declaration file for module 'storage-factory'. 'my-project/node_modules/storage-factory/lib/esm/index.js' implicitly has an 'any' type.
  There are types at 'my-project/node_modules/storage-factory/lib/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'storage-factory' library may need to update its package.json or typings. ts(7016)

I think this is because package.json needs to include types explicitly on the ESM export, like this?

  "exports": {
    "require": {
      "types": "./lib/index.d.ts",
      "default": "./lib/index.js"
    },
    "import": {
      "types": "./lib/index.d.ts",
      "default": "./lib/esm/index.js"
    }
  }
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

1 participant