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...

  1. npm install --save flux-sdk;
  2. 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...

  1. npm install --save flux-sdk;
  2. 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 frontend ng 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
Add a ment  | 

3 Answers 3

Reset to default 5

I 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 called 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;
}

  • Then just include typings in your tsconfig.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.

本文标签: