Could not find a declaration file for module, @types/...@latest' is not in the npm registry

2k views Asked by At

I install react-pivottable then when I import this

import PivotTableUI from 'react-pivottable';

I am gettig this as error as vscode warning

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

Then I type npm install @types/react-pivottable

But at this time I am getting this error as console output

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2freact-pivottable - Not found
npm ERR! 404
npm ERR! 404  '@types/react-pivottable@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\tphusnua\AppData\Roaming\npm-cache\_logs\2020-07-28T08_48_48_808Z-debug.log

What should I do ? Thank You.

1

There are 1 answers

2
Tejeshree On BEST ANSWER

Another thing that you can do is mentioned in the error :(since you already tried npm install and it did not work)

Could not find a declaration file for module 'react-pivottable'.
 '.../node_modules/react-pivottable/PivotTableUI.js' implicitly has an 'any' type.
 Try `npm install @types/react-pivottable` if it exists or add a new declaration (.d.ts) 
 file containing `declare module 'react-pivottable';`ts(7016)
  1. create a typings or type folder(name it as you want)
  2. have a file created - decalaration.d.ts and in that file write declare module 'react-pivottable;
  3. in tsconfig.json add "typeRoots": ["./typings","node_modules/@types"] <- path to your typings folder and also path to types in node_modules so that if types are present in node_modules it will be referred

Note : This can also be resolved by adding following property to tsconfig.json:

"noImplicitAny": false