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 come here.
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:
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;
}
typings
in your tsconfig.json
:{
"compilerOptions": {
// ...
},
"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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.