2

我有一个角度自定义库@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"
  },

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

现在,我要删除我的node_modulesand yarn.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都消失了。任何人都知道为什么以及如何解决它?

4

1 回答 1

0

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

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

我的设置:

Angular CLI 11.0.2 节点:12.18.2 Yarn 1.22.4

附带说明:

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

"@angular/material": "11.0.1",
"@angular/common": "^10.0.14",
"@angular/cli": "9.1.9"
于 2020-11-30T17:26:17.663 回答