找不到模块的声明文件,@types/...@latest' 不在 npm 注册表中

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

我安装 react-pivottable 然后当我导入它时

import PivotTableUI from 'react-pivottable';

我将此视为错误 vscode 警告

 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)

然后我输入npm install @types/react-pivottable

但此时我收到此错误作为控制台输出

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\_logs20-07-28T08_48_48_808Z-debug.log

我该怎么办?谢谢。

错误中提到了您可以做的另一件事 :(因为您已经尝试过 npm install 但它没有工作)

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. 创建一个 typings 或 type 文件夹(随意命名)
  2. 创建一个文件 - decalaration.d.ts 并在该文件中写入 declare module 'react-pivottable;
  3. in tsconfig.json 添加 "typeRoots": ["./typings","node_modules/@types"] <- typings 文件夹的路径以及 node_modules 中类型的路径,这样如果类型是出现在 node_modules 它将被引用

注意 :这也可以通过在tsconfig.json中添加以下属性来解决:

"noImplicitAny": false