HarmonyOS 鸿蒙Next 求助Cannot find module '@ohos/library' or its corresponding type declarations. <tsCheck>

HarmonyOS 鸿蒙Next 求助Cannot find module ‘@ohos/library’ or its corresponding type declarations. <tsCheck> 各位大佬!!!

Cannot find module '[@ohos](/user/ohos)/library' or its corresponding type declarations. 这个报错咋解决…

我找到这个方案(https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V2/faq-compiling-and-building-0000001233028585-V2#section2074611341974)发现也解决不了

我项目没有application包


更多关于HarmonyOS 鸿蒙Next 求助Cannot find module '@ohos/library' or its corresponding type declarations. <tsCheck>的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

看代码,Butons是用户自定义的一个静态库,通过配置

引用​,你的依赖里面没有这个组件

更多关于HarmonyOS 鸿蒙Next 求助Cannot find module '@ohos/library' or its corresponding type declarations. <tsCheck>的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


成功了!
新建了一个名为“library”的module
在oh-package.json5加了

{
  "dependencies": {
    "@ohos/library": "file:../library"
  }
}
错误通常是由于项目中没有正确安装或引用 `@ohos/library` 模块导致的。以下是一些可能的原因和解决方法:

1. 模块未安装:确保 `@ohos/library` 已经通过 `npm` 或 `yarn` 安装。可以使用以下命令进行安装:
   ```bash
   npm install @ohos/library

yarn add @ohos/library
  1. 模块路径问题:检查 tsconfig.json 文件,确保模块路径配置正确。baseUrlpaths 配置可能需要调整以正确解析模块路径。

  2. 类型声明缺失:如果 @ohos/library 没有提供类型声明文件,可能需要手动添加 .d.ts 文件或使用 @types 包。

  3. 项目结构问题:确保项目结构正确,模块引用路径与项目结构一致。

  4. IDE 配置:某些 IDE(如 VSCode)可能需要重新加载项目或更新 TypeScript 配置以正确识别模块。

检查以上几点,通常可以解决该错误。

这个错误提示表明 TypeScript 编译器无法找到 [@ohos](/user/ohos)/library 模块或其类型声明文件。可能的原因和解决方法如下:

  1. 模块未安装:确保你已经在项目中正确安装了 [@ohos](/user/ohos)/library 模块。可以通过以下命令安装:

    npm install [@ohos](/user/ohos)/library
    
  2. 路径问题:检查 tsconfig.json 文件中的 pathsbaseUrl 配置,确保模块路径正确。

  3. 类型声明缺失:如果模块没有自带类型声明文件,你可以尝试安装对应的类型声明包,或者手动创建 d.ts 文件。

  4. 清理缓存:有时候 TypeScript 编译器缓存可能会导致问题,尝试清理缓存并重新编译:

    npx tsc --build --clean
    

如果问题仍然存在,建议检查模块的文档或联系开发者社区获取更多帮助。

回到顶部