0

I am trying to use the type definitions in the callbag library. This library declares its type definition file in its package.json. It is not uploaded to DefinitelyTyped. When I try to import the library, I get the error:

Cannot find module 'callbag'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

This is how I import it:

import type { Sink } from 'callbag';

Here is my tsconfig.json:

{
  "compilerOptions": {
    "module": "es6",
    "noEmitOnError": true,
    "outDir": "./dist",
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "es5"
  },
  "include": ["./src/**/*"]
}

I also tried adding "types": ["callbag"] to the tsconfig.json, but it didn't work.

How do I get typescript to recognize the types for this library?

Eva
  • 4,397
  • 5
  • 43
  • 65
  • At first, your import statement looks correct. Could you paste in your `tsconfig.json` into your question (using edit)? – Shinigami Nov 07 '20 at 15:59
  • Does this answer your question? [Typescript 2.0. "types" field in tsconfig.json](https://stackoverflow.com/questions/39826848/typescript-2-0-types-field-in-tsconfig-json) – Etheryte Nov 07 '20 at 16:00
  • I have added the tsconfig.json. The linked answer does not work for me. I tried it with types in my tsconfig.json. – Eva Nov 07 '20 at 16:26
  • @Eva can you please try setting "moduleResolution": "node" in tsconfig.json, as evident in error. – Hemant Kumar Nov 07 '20 at 17:21
  • That worked, but can you explain why? AFAICT the module was es6. Why does it also need to be set to node? – Eva Nov 07 '20 at 17:33

1 Answers1

0

As posted in the comments, I needed to add "moduleResolution": "node" to my tsconfig.json. Not sure why because nothing that I working on is related to Node.js. But that's what worked.

Eva
  • 4,397
  • 5
  • 43
  • 65