Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types not found when moduleResolution: node16 is set for typescript #288

Closed
sorgloomer opened this issue Aug 2, 2022 · 0 comments · Fixed by #292
Closed

Types not found when moduleResolution: node16 is set for typescript #288

sorgloomer opened this issue Aug 2, 2022 · 0 comments · Fixed by #292

Comments

@sorgloomer
Copy link

Describe the bug

Getting

main.ts:1:24 - error TS7016: Could not find a declaration file for module 'ngrok'. '.../node_modules/ngrok/index.js' implicitly has an 'any' type.

when trying to import in a project with moduleResolution: node16.

To Reproduce

package.json

{
  "dependencies": {
    "ngrok": "4.3.1",
    "typescript": "4.7.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "moduleResolution": "Node16",
    "noImplicitAny": true
  }
}

main.ts

import * as ngrok from 'ngrok';

and then run:

tsc

Output I get:

$ tsc
main.ts:1:24 - error TS7016: Could not find a declaration file for module 'ngrok'. '.../node_modules/ngrok/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/ngrok` if it exists or add a new declaration (.d.ts) file containing `declare module 'ngrok';`

1 import * as ngrok from 'ngrok';
                         ~~~~~~~


Found 1 error in main.ts:1

Additional context

My intent in this example is to import ngrok using require, and this is what's happening, but typescript doesn't seem to pick up the .d.ts file.

Typescripts esm support is not without controversies. One of them is that they are more strict about the location of .d.ts files: microsoft/TypeScript#49160 . The most straightforward solution seems to be renaming ngrok.d.ts to index.d.ts, but there might be better ways I am not aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant