![](/img/trans.png)
[英]Cannot find module 'graphql-hooks' or its corresponding type declarations
[英]Can't find module or its corresponding type declarations when trying to import SDK in Angular Project
当前尝试在现有的 Angular 项目中使用 SDK,我们无法找到以下问题的原因。
这是错误的图像:
Cannot find module 'flux-sdk' or its corresponding type declarations
在进行了一些挖掘之后,我们发现了具有相同问题的各种帖子,并且几乎尝试了我们能找到的所有内容,但仍然无法解决错误。
脚步...
npm install --save flux-sdk;
import Flux from 'flux-sdk';
import
失败(步骤 2),出现上述错误。
我们不确定为什么会发生这种情况,因为我们已经尝试了在网上找到的其他解决方案,但无法解决我来这里的问题。
我认为您可以通过以下步骤为一个没有类型定义的包添加类型,例如 Angular 项目中的这个包flux-sdk
:
typings
目录,然后为这个包创建类型,它可能被称为flux-sdk.d.ts
: typings/flux-sdk.d.ts
:
declare module 'flux-sdk' {
const flux: any; // you can define whatever is now exported
export default flux;
}
typings
在tsconfig.json
:{
"compilerOptions": {
// ...
},
"include": [
"typings"
],
}
请尝试这些解决方案。
方法 1:只需使用require
而不是import
。
// import { Flux } from 'flux-sdk'
const Flux = require('flux-sdk');
方法 2:如果要使用import
请尝试替换tsconfig.json
这些行
"noImplicitAny": false,
"allowJs": true,
我希望他们能帮助你,谢谢。
也许您使用旧的 package-lock.json。 请删除 package-lock.json&node_modules 并重新安装节点模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.