如何解决尝试在Angular Project中导入SDK时找不到模块或其对应的类型声明
当前正在尝试在现有的Angular项目中使用SDK,但我们无法找到导致以下问题的原因。
以下是错误的图片:
let Cat = {
name:"catty",color:"gray"
}
secound example you pass the whole object like this
function ( Cat ) {}
function ( { name,color } ) {
/// here you can use name and color as "catty" and "gray"
}
if you use the first expample you would have to specify the parameters like this
function (Cat.name,Cat.color) {
}
进行了一些挖掘之后,我们发现了具有相同问题的各种帖子,并尝试了我们可以找到的所有内容,但仍然无法解决错误。
步骤...
-
Cannot find module 'flux-sdk' or its corresponding type declarations
-
npm install --save flux-sdk;
import Flux from 'flux-sdk';
(第2步)失败,出现上面显示的错误。
我们不确定为什么会这样,因为我们尝试了在线找到的其他解决方案,但无法解决我遇到的问题。
解决方法
请尝试这些解决方案。
方法1:
只需使用require
而不是import
。
// import { Flux } from 'flux-sdk'
const Flux = require('flux-sdk');
方法2:
如果要使用tsconfig.json
,请尝试在import
中替换这些行
"noImplicitAny": false,"allowJs": true,
我希望他们能帮助您,谢谢。
,我认为您可以通过以下步骤为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"
],}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。