Skip to content

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

@mltsy

Description

@mltsy

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"
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions