Skip to content

Types fail to resolve in TypeScript 5.x in ESM  #1012

@AaronFriel

Description

@AaronFriel

When importing compromise, I see this error:

import nlp from 'compromise';

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

I've not seen this strategy of separating src and types into separate folders like this, I think that's where the issue might be?

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022","DOM"],
    "module": "nodenext"
  }
}

Setting moduleResolution to bundler does not seem to help, nor does setting module to Node16 or ESNext or others.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions