Friday, 20 October 2023

How to export type definitions and use them via npm link of a local package?

I'm creating a supertest alternative called tepper. I'm trying to publish the package both as ESM and CJS. The problem I'm having is that a consumer of the library isn't able to find the type definitions.

In order to test it, I've created a script (you can find it here), that generates a brand-new NestJS project, and tries to use the library by installing it locally using a relative path (npm install --save-dev ../../../..)

The problem is that I'm having an TS2307: Cannot find module 'tepper' or its corresponding type declarations error (here you can see the error on Github Actions).

I've exported the types in package.json as I'm supposed:

{
  "exports": {
    ".": {
      "types": "./dist/types/tepper.d.ts",
      "require": "./dist/cjs/tepper.js",
      "import": "./dist/esm/tepper.js",
      "default": "./dist/esm/tepper.js"
    }
  }
}

Thanks!



from How to export type definitions and use them via npm link of a local package?

No comments:

Post a Comment