Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法将js位组件导入ts项目-`找不到模块的声明文件`_Javascript_Typescript_Bit.dev - Fatal编程技术网

Javascript 无法将js位组件导入ts项目-`找不到模块的声明文件`

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

在尝试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/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}”