typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
31.69k stars 996 forks source link

Cannot import husky v9 with moduleResolution: "node" #1396

Open apottere opened 3 months ago

apottere commented 3 months ago

Description

Typescript can't find types for a husky v9 import when using "moduleResolution": "node". It seems to work with "moduleResolution": "nodenext" (but that causes other issues for me.

It's unclear from the release notes whether this is intended as part of the nodejs 14/16 support drop. Feel free to close if it's expected.

Steps to Reproduce

  1. https://github.com/apottere/husky-v9-moduleresolution-node
  2. pnpm i (I also tested with npm, no difference)
  3. npx tsc -p tsconfig-nodenext.json - success
  4. npx tsc -p tsconfig-node.json

    index.ts:1:19 - error TS2307: Cannot find module 'husky' or its corresponding type declarations.
    
    1 import husky from 'husky';
                        ~~~~~~~
    
    Found 1 error in index.ts:1
    

This also confirms it's the types in the published package causing this issue with this particular moduleResolution, not some quirk of my setup: https://arethetypeswrong.github.io/?p=husky%409.0.11

Again, not sure if this is intended.

typicode commented 3 months ago

Thanks for the test repo.

I'm sorry I don't know. Husky doesn't do anything fancy with TS so I'm not sure why it's failing.

There's no build step so you can check directly the code, it's the one that is published.

Do you have the same issue with husky v9.0.8?

apottere commented 3 months ago

Looks like it works in 9.0.8

apottere commented 3 months ago

AFAICT adding "types": "index.d.mts", to the package.json gets resolution working for both, but I'm not sure if there are any drawbacks there.