reactjs - 找不到模块的声明文件,@types/...@latest' 不在 npm 注册表中
问题描述
我安装 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\_logs\2020-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)
- 创建一个类型或类型文件夹(根据需要命名)
- 创建了一个文件 - decalation.d.ts 并在该文件中写入
declare module 'react-pivottable;
- 在tsconfig.json添加
"typeRoots": ["./typings","node_modules/@types"]
<- 到您的类型文件夹的路径以及 node_modules 中类型的路径,以便如果类型存在于 node_modules 中,它将被引用
注意:这也可以通过向tsconfig.json添加以下属性来解决:
"noImplicitAny": false
推荐阅读
- javascript - 浏览器不等待特定图像加载
- ibm-cloud-infrastructure - 使用 reloados REST API 重新加载不同的操作系统
- react-native - 如何在应用程序打开时渲染堆栈屏幕而不将其放入抽屉屏幕
- vb.net - 如何在发布后替换资源 .txt 文件而不会出错
- javascript - 将拖放内容保存到 html 中的 localStorage
- android - 当 LinearLayout 移动到另一个地方时,按钮丢失 onClickListener
- javascript - 画外音不是阅读输入的标签,只是内容 - safari
- javascript - 如果另一个单元格的颜色发生更改,则在 Google 表格中为一个单元格添加时间戳
- javascript - 在页面加载时运行 chrome 扩展
- regex - 将大写 URL 重定向到特定于子文件夹的小写版本