无法找到模块“react-payment-inputs”的声明文件

来源:12-7 【UI搭建】在线支付页面初始化

蹩脚的蚂蚁

2022-09-04

老师您好,我通过npm install react-payment-inputs 安装了react-payment-inputs。但是编译还是报错,说找不到这个module。vscode 提示下面错误:
无法找到模块“react-payment-inputs”的声明文件。“C:/Users/86173/Desktop/chenxiao/project/react-travel/node_modules/react-payment-inputs/lib/index.js”隐式拥有 “any” 类型。
尝试使用 npm i --save-dev @types/react-payment-inputs (如果存在),或者添加一个包含 declare module 'react-payment-inputs'; 的新声明(.d.ts)文件ts(7016)

下面是编译报的错:
ERROR in ./node_modules/react-payment-inputs/es/PaymentInputsWrapper.js 3:0-48
Module not found: Error: Can’t resolve ‘styled-components’ in ‘C:\Users\86173\Desktop\chenxiao\project\react-travel\node_modules\react-payment-inputs\es’

ERROR in ./node_modules/react-payment-inputs/es/index.js 9:0-27
Module not found: Error: Can’t resolve ‘styled-components’ in 'C:\Users\86173\Desktop\chenxiao\project\react-travel\node_modules\react-payment-inputs\es’
webpack compiled with 2 errors and 1 warning

这是什么原因呢?谢谢老师。

写回答

2回答

那辰4403872

2022-09-05

试试这个

npm i react-payment-inputs --legacy-peer-deps


1
1
慕粉3831983
这种方式还是报一样的错误
2022-10-27
共1条回复

阿莱克斯刘

2022-11-29

这个问题我也出现了,问题并非来自课程项目,而是react-payment-inputs这个依赖包出了问题,目前我怀疑这个依赖包对node不同版本支持有问题。

解决方式就是请同学们不要再使用这个依赖了。因为在实际工作中,如果一个依赖如此不稳定我们是不应该使用的。另外,如果一个项目在github上的星星比较少,千万不要用。

https://img.mukewang.com/szimg/6385ba8509e14c3124650791.jpg

所以react-payment-inputs组件比较坑,请同学从项目中删除,换成ant design的input box吧,丑是丑一点,但是只要功能完整能继续课程就可以。

当然,我也会积极寻找替代方案,一旦找到更好的依赖包会马上更新视频。


0
0

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

1993 学习 · 1015 问题

查看课程