honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
18.65k stars 523 forks source link

Types exports are incorrect in package.json #3284

Open marcomuser opened 1 month ago

marcomuser commented 1 month ago

What version of Hono are you using?

4.5.5

What runtime/platform is your app running on?

Node.js

What steps can reproduce the bug?

According to Are The Types Wrong? the types for hono are not set up correctly. The main issue is that the exports property in package.json defines only one type for both the .cjs as well as the .js file:

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

This is, however, not ideal. It should export a separate type declaration file for each:

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

What is the expected behavior?

I should be able to import hono in a Node.js ESM project with moduleResolution "node16" without any issues.

What do you see instead?

Under moduleResolution "nodenext" or "node16" in a ESM project, this leads to an import which resolves to a CJS type declaration file, but a ESM JavaScript file.

Additional information

For context, this PR fixed the same issue in the openapi-fetch package: https://github.com/openapi-ts/openapi-typescript/pull/1360.

yusukebe commented 1 month ago

Hi @marcomuser !

This is a good suggestion. Can you work on it?

marcomuser commented 1 month ago

Sure! :) Might take a couple of days till I get to it but I'll create a PR!

yusukebe commented 1 month ago

@marcomuser

Thanks!!