Home > OS >  Problems using a js module is ts project
Problems using a js module is ts project

Time:06-14

I have a react ts project where I installed a pure js module: crypto-prices. Considering this module doesn't have any @types source, I created a decs.d.ts file with:

declare module "crypto-prices"

This removes the IDE issue. Yet, when I try to use the cryptoPrice modules through

import cryptoPrice from 'crypto-prices'

I get the following error:

Can't resolve 'crypto-prices' in ...

CodePudding user response:

Import it like this,

import * as cryptoPrice from 'crypto-prices'

CodePudding user response:

You need to include decs.d.ts in tsconfig.json. If decs.d.ts is in the same folder as tsconfig.json it should look something like below:

tsconfig.json

{
    "include": [
        "./src/**/*",
        "./decs.d.ts"
    ],
    "compilerOptions": {
        ...
    }
}
  • Related