Home > Back-end >  React - Unable to import a library component that exists in node_modules folder
React - Unable to import a library component that exists in node_modules folder

Time:07-10

I've installed 'react-image-gallery' library using yarn

yarn add react-image-gallery

And it now exists in my node_modules folder, but it says "Could not find a declaration file for module 'react-image-gallery'." when I try to import it.
How can I make it importable ?
enter image description here

CodePudding user response:

When using some third-party packages as dependencies, not all of those packages are written in TypeScript. Therefore the packages developers provide also an installation for the type declarations if other developers want to use those types in their TypeScript projects.
In your case to install the package react-image-gallery :

  1. first yarn add react-image-gallery
  2. then (when usinig TypeScript) yarn add @types/react-image-gallery

If you want to know more about Type Declarations check this official link

  • Related