未安装我的库的依赖包(@angular/material/core not found)

Posted

技术标签:

【中文标题】未安装我的库的依赖包(@angular/material/core not found)【英文标题】:Package which is a dependency of my library isn't installed (@angular/material/core not found) 【发布时间】:2021-03-12 14:24:21 【问题描述】:

我有一个 Angular 自定义库 @foo/bar,它具有以下依赖项:

"peerDependencies": 
    "@angular/common": "^10.0.14",
    "@angular/core": "^10.0.14"
  ,
  "dependencies": 
    "@angular/material": "11.0.1",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "@custom-library-1": "^0.0.5",
    "@custom-library-2": "^0.0.1",
    "tslib": "^2.0.0"
  ,

当我在一个干净的项目(只有一个空的 package.json)中使用 yarn add @foo/bar 安装这个库并导航到 node_modules/@angular 时,我看到了文件夹 @angular/material/core

现在,我要删除我的 node_modulesyarn.lock,并向该项目添加以下依赖项:

"dependencies": 
    "@angular/animations": "9.1.11",
    "@angular/common": "9.1.11",
    "@angular/compiler": "9.1.11",
    "@angular/core": "9.1.11",
    "@angular/forms": "9.1.11",
    "@angular/material-moment-adapter": "^11.0.1",
    "@angular/platform-browser": "9.1.11",
    "@angular/platform-browser-dynamic": "9.1.11",
    "@angular/router": "9.1.11",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "@ngxs/store": "^3.7.0",
    "@nrwl/angular": "9.4.4",
    "@custom-library-1": "^0.0.1",
    "@custom-library-1": "^0.0.5",
    "core-js": "^2.5.4",
    "rxjs": "6.5.5",
    "zone.js": "^0.9.1",
    "@foo/bar": "0.0.1"
  ,
  "devDependencies": 
    "@angular-devkit/build-angular": "0.901.9",
    "@angular/cli": "9.1.9",
    "@angular/compiler-cli": "9.1.11",
    "@angular/language-service": "9.1.11",
    "@biesbjerg/ngx-translate-extract": "^4.2.0",
    "@nrwl/cypress": "9.4.4",
    "@nrwl/jest": "9.4.4",
    "@nrwl/workspace": "9.4.4",
    "@types/jest": "25.1.4",
    "@types/node": "~8.9.4",
    "aws-sdk": "^2.585.0",
    "codelyzer": "~5.0.1",
    "cypress": "3.8.2",
    "dotenv": "6.2.0",
    "eslint": "6.8.0",
    "express-serve-static-core": "^0.1.1",
    "jest": "25.2.4",
    "jest-preset-angular": "8.1.3",
    "prettier": "2.0.4",
    "readdir-enhanced": "^5.1.1",
    "ts-jest": "25.2.1",
    "ts-node": "~7.0.0",
    "tslint": "6.0.0",
    "typescript": "3.8.3"
  

现在当我尝试构建项目时,我遇到了这个错误:

ERROR in The target entry-point "@foo/bar" has missing dependencies:
 - @angular/material/core

另外,当我导航到node_modules/@angular 时,我注意到整个@angular/material 都消失了。有谁知道为什么以及如何解决?

【问题讨论】:

【参考方案1】:

我假设您的yarn install 命令运行没有任何问题,否则可能是您的安装失败并导致node_modules 文件夹不完整。

我使用此设置创建了一个项目,但没有遇到此问题。 这可能是您的工具(纱线、角度 cli)的问题。

我的设置:

Angular CLI 11.0.2 节点:12.18.2 纱线 1.22.4

附带说明:

您正在创建不同 Angular 版本的组合,这可能也无济于事,例如:

"@angular/material": "11.0.1",
"@angular/common": "^10.0.14",
"@angular/cli": "9.1.9"

【讨论】:

将 Angular 升级到相同的最新版本确实解决了另一个问题,但不幸的是不是问题所在

以上是关于未安装我的库的依赖包(@angular/material/core not found)的主要内容,如果未能解决你的问题,请参考以下文章

查看python第三方库的依赖

查看python第三方库的依赖

在现代CMake项目中存档静态依赖项

ClassNotFoundException 当“实现”用于库的库依赖时

Git:如何管理 C# 库的依赖关系? [关闭]

静态链接库的动态 DLL