admin管理员组文章数量:1279019
Currently attempting to use an SDK in an existing Angular project and we are unable to find the cause to the following problem.
Here is an image of the error:
Cannot find module 'flux-sdk' or its corresponding type declarations
After doing some digging we found various post with the same issue and have tried just about everything we could find and are still unable to solve the error.
Steps...
npm install --save flux-sdk;
import Flux from 'flux-sdk';
Fails on import
( Step 2 ) with the error shown above.
We are not sure why this is happening and because we have tried the other solutions found online and unable to solve the issue I e here.
Currently attempting to use an SDK in an existing Angular project and we are unable to find the cause to the following problem.
Here is an image of the error:
Cannot find module 'flux-sdk' or its corresponding type declarations
After doing some digging we found various post with the same issue and have tried just about everything we could find and are still unable to solve the error.
Steps...
npm install --save flux-sdk;
import Flux from 'flux-sdk';
Fails on import
( Step 2 ) with the error shown above.
We are not sure why this is happening and because we have tried the other solutions found online and unable to solve the issue I e here.
Share Improve this question edited Nov 7, 2020 at 14:35 SwissCodeMen 4,89510 gold badges28 silver badges36 bronze badges asked Nov 7, 2020 at 8:07 ETHanETHan 2071 gold badge4 silver badges19 bronze badges 4-
Does the
flux-sdk
NPM package have type declarations included? If it doesn't, did you install the@types/flux-sdk
package as a dev dependency? – Edric Commented Nov 7, 2020 at 9:46 -
Close the IDE and reopen it, make a
npm install
after reopen and then start the frontendng serve
. I also had the problem that the modules where imported were not found and carried out exactly these steps and this removed this message – SwissCodeMen Commented Nov 7, 2020 at 9:56 - @Edric no types – ETHan Commented Nov 9, 2020 at 17:57
- @SwissCodeMen I tried this and it still doesn't work. – ETHan Commented Nov 9, 2020 at 17:57
3 Answers
Reset to default 5I think you could achieve adding typing for a package which doesn't have type definition like this package flux-sdk
in an Angular project by following steps:
- Create a
typings
directory at the root level then create the typing for this package which is likely calledflux-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;
}
- Then just include
typings
in yourtsconfig.json
:
{
"pilerOptions": {
// ...
},
"include": [
"typings"
],
}
Kindly try these solutions.
Method 1:
Simply use require
instead of import
.
// import { Flux } from 'flux-sdk'
const Flux = require('flux-sdk');
Method 2:
Try to replace these line in the tsconfig.json
if you want use import
"noImplicitAny": false,
"allowJs": true,
I hope they would help you, thanks.
Maybe you use old package-lock.json. Please delete package-lock.json&node_modules and reinstall node modules.
本文标签:
版权声明:本文标题:javascript - Can't find module or its corresponding type declarations when trying to import SDK in Angular Project - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741236380a2363098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论