简体   繁体   English

在 Angular 项目中尝试导入 SDK 时找不到模块或其对应的类型声明

[英]Can't find module or its corresponding type declarations when trying to import SDK in Angular Project

Currently attempting to use an SDK in an existing Angular project and we are unable to find the cause to the following problem.当前尝试在现有的 Angular 项目中使用 SDK,我们无法找到以下问题的原因。

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. import失败(步骤 2),出现上述错误。

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:我认为您可以通过以下步骤为一个没有类型定义的包添加类型,例如 Angular 项目中的这个包flux-sdk

  • 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

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

  • Then just include typings in your tsconfig.json :然后,只需包括typingstsconfig.json
{
  "compilerOptions": {
    // ...
  },
  "include": [
    "typings"
  ],
}

Kindly try these solutions.请尝试这些解决方案。

Method 1: Simply use require instead of import .方法 1:只需使用require而不是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方法 2:如果要使用import请尝试替换tsconfig.json这些行

"noImplicitAny": false,
"allowJs": true,

I hope they would help you, thanks.我希望他们能帮助你,谢谢。

Maybe you use old package-lock.json.也许您使用旧的 package-lock.json。 Please delete package-lock.json&node_modules and reinstall node modules.请删除 package-lock.json&node_modules 并重新安装节点模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块“graphql-hooks”或其相应的类型声明 - Cannot find module 'graphql-hooks' or its corresponding type declarations 找不到模块“./App.svelte”或其对应的类型声明 - Cannot find module './App.svelte' or its corresponding type declarations React,Storybook - TS2307:找不到模块“按钮”或其相应的类型声明 CAN SB RESOLVE? - React,Storybook - TS2307: Cannot find module 'Button' or its corresponding type declarations CAN SB RESOLVE? 在 vercel 上部署我的 next.js 项目,找不到模块“react-icons/Fa”或其相应的类型声明 - deploy my next.js project on vercel, Cannot find module 'react-icons/Fa' or its corresponding type declarations 如何解决找不到找不到模块'../home/featuredRooms'或其对应的类型声明。? - how to solve cannot find Cannot find module '../home/featuredRooms' or its corresponding type declarations.? 找不到模块“@react-navigation/native”或其相应的类型声明 - Cannot find module '@react-navigation/native' or its corresponding type declarations Docker/Next js:: 找不到模块“@mui/x-date-pickers/AdapterDateFns”或其相应的类型声明 - Docker/Next js :: Cannot find module '@mui/x-date-pickers/AdapterDateFns' or its corresponding type declarations 为什么我收到此错误找不到模块“nestjs/common”或其相应的类型声明 - Why I got this error Cannot find module 'nestjs/common' or its corresponding type declarations VueJS/Typescript - 找不到模块“./components/Navigation”或其相应的类型声明 - VueJS/Typescript - Cannot find module './components/Navigation' or its corresponding type declarations ReScript,TypeScript:找不到模块“@rescript/react/src/ReactDOM.gen”或其相应的类型声明 - ReScript, TypeScript: Cannot find module '@rescript/react/src/ReactDOM.gen' or its corresponding type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM