Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "Could not find a declaration file for module 'react-search-input'"

I am trying install react-input-search. I have error:

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

like image 570
Umbro Avatar asked May 29 '19 00:05

Umbro


People also ask

Could not find a declaration file for module react?

The error "could not find declaration file for module 'react'" occurs when TypeScript cannot find the type declaration for a react-related module. To solve the error install the types for the module by running the command from the error message, e.g. npm install -D @types/react .

Could not find a declaration file for module react JSX runtime?

When you have this error, it is usually because you installed a library and you didn't install the types of that library. To fix this error, you need to install @types/library-name using your package manager (npm or yarn).


3 Answers

This is a common error that you can simply solve by creating an index.d.ts file and then add a declaration line like this:

declare module 'react-input-search';

You can save this file anywhere you wish but make sure to add the filepath to tsconfig.json like this "typeRoots": [ "types/index.d.ts" ],

This is assuming you saved it in types/index.d.ts

like image 141
Akintunde Avatar answered Oct 28 '22 21:10

Akintunde


Typescript should go with Typescript NPM package, the Typescript NPM package had prefix @types/ on it name. The NPM package react-search-input do not had Typescript package for it yet, then you can simple fix by following

  1. Create file with name globals.d.ts and put on your source root of Typescript watcher folder
  2. Put declare module 'react-search-input' on that file

And it should working fine

like image 16
Vo Kim Nguyen Avatar answered Oct 28 '22 22:10

Vo Kim Nguyen


It's a typescript error. It means that there is no type declarations in 'react-input-search' library. There is no package 'react-input-search' with types for it, so you need to declare usage of these library in your project by creating a file with extension .d.ts (for example libraries.d.ts) and insert a line declare module 'react-search-input'; into it.

like image 1
Alex Gessen Avatar answered Oct 28 '22 20:10

Alex Gessen