0

I am using a library react-excel-renderer in Typescript but I get this message while importing it:

Could not find a declaration file for module 'react-excel-renderer'. 'react-flask-app/node_modules/react-excel-renderer/build/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-excel-renderer` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-excel-renderer';`

I tried installing types but since they don't exist in npm, I added a @types folder in src with

declare module 'react-excel-renderer';

or

declare module '*';

I tried naming the file react-excel-renderer.d.ts, global.d.ts, and even .d.ts but none of these seem to work. I still see the same error upon importing this library.

What else should I try?

tsconfig file:

  "include": [
    "src", "src/@types/.d.ts", "@types"
  ]
1

1 Answer 1

0

Inside my project I created a folder called @types and added it to tsconfig.json for find all required types from it . So it looks somewhat like this -

"typeRoots": [
  "../node_modules/@types",
  "../@types"
]

And inside that I created a file called alltypes.d.ts . To find the unknown types from it . so for me these were the unknown types and I added it over there.

declare module 'react-excel-renderer';

So now the typescript didn't complain about the types not found anymore.

1
  • the @types folder is in the root or the src directory? I tried with root and it doesn't seem to work for me.
    – user13067694
    Jun 23, 2021 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.