Javascript 无法将js位组件导入ts项目-`找不到模块的声明文件`
在尝试npm将javascript组件安装到typescript项目中时,我因缺少Javascript 无法将js位组件导入ts项目-`找不到模块的声明文件`,javascript,typescript,bit.dev,Javascript,Typescript,Bit.dev,在尝试npm将javascript组件安装到typescript项目中时,我因缺少d.ts文件或@types组件而收到typescript错误: TypeScript error in /Users/oded/code/base-components/src/App.tsx(3,33): Could not find a declaration file for module '@bit/bit.web.components.comment-carousel'. '/Users/oded/cod
d.ts
文件或@types
组件而收到typescript错误:
TypeScript error in /Users/oded/code/base-components/src/App.tsx(3,33):
Could not find a declaration file for module '@bit/bit.web.components.comment-carousel'. '/Users/oded/code/base-components/node_modules/@bit/bit.web.components.comment-carousel/dist/src/components/comment-carousel/index.js' implicitly has an 'any' type.
Try `npm install @types/bit.web.components.comment-carousel` if it exists or add a new declaration (.d.ts) file containing `declare module '@bit/bit.web.components.comment-carousel';
我是另一个项目中@bit/bit.web.components.comment carousel
组件的作者
我可以想出两种方法来解决这个问题:
bit将它从最初编写它的作者项目(以及它当前使用的位置)中弹出,并将d.ts
添加到组件中
bit导入组件
并在我的消费项目中对其进行修改,但感觉有点过头了有没有更好的方法来实现这一点 我认为这不是一个小问题,而是一个TypeScript问题,也许你可以将导入组件的目录添加到
tsconfig.json
的exclude选项中,排除tsconfig.json中的node_modules
对我不起作用。见下文。对我来说,有效的方法是在组件导入过程中添加@ts ignore
js/@ts忽略从“@bit/bit.web.components.comment carousel”导入{CommentCarousel}”代码>我认为这不是一个小问题,而是一个类型脚本问题,也许你可以将导入组件的目录添加到tsconfig.json
排除tsconfig.json中的node_modules
的exclude选项中。见下文。对我来说,有效的方法是在组件导入过程中添加@ts ignore
js/@ts忽略从“@bit/bit.web.components.comment carousel”导入{CommentCarousel}”代码>