【问题标题】:Collection "@candiman/website" cannot be resolved集合“@candiman/website”无法解析
【发布时间】:2019-08-14 16:33:21
【问题描述】:

我检查了Collection “@schematics/angular” cannot be resolved ,它不是重复的。

我创建了自己的原理图,当我尝试使用 ng add @candiman/website@0.0.5-beta.3 使用它时,我遇到了以下错误。

我认为问题在于collection.json 没有打包并运送到npm package,因为ng-packgr 不包含JSON 文件

因此,物理 collection.json 不存在于 npm 包文件夹中,当原理图搜索 collection.json 文件时失败。

Collection "@candiman/website" cannot be resolved.
Error: Collection "@candiman/website" cannot be resolved.
    at NodeModulesEngineHost._resolveCollectionPath (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:91:15)
    at NodeModulesEngineHost.createCollectionDescription (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:111:27)
    at SchematicEngine._createCollectionDescription (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular-devkit/schematics/src/engine/engine.js:147:40)
    at SchematicEngine.createCollection (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular-devkit/schematics/src/engine/engine.js:140:43)
    at AddCommand.getCollection (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular/cli/models/schematic-command.js:123:35)
    at AddCommand.runSchematic (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular/cli/models/schematic-command.js:262:50)
    at AddCommand.executeSchematic (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular/cli/commands/add-impl.js:134:31)
    at AddCommand.run (/Users/aniruddh/aniruddh/develop/experiment/schematics-exp/sche-ex1/node_modules/@angular/cli/commands/add-impl.js:105:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)

@candiman/website@0.0.5-beta.3 的原理图现在可以在npm 获得,如果有人想尝试一下。

angular库的源码可以在project source which publishes npm package with schematics找到

【问题讨论】:

  • 问题未命名无法解决集合“@candiman/website”。你确定你在看正确的问题吗?
  • 哦,我会改的。
  • 我可以看看你的源代码吗?您尚未添加任何指向您的源代码或您的包中的网站的链接。
  • @Edric 也在更新问题

标签: angular angular-schematics


【解决方案1】:

这是因为您声明的依赖项的package.json 文件没有schematics 属性,该属性是原理图定义文件(JSON 文件)的路径:

{
  "name": "@candiman/website",
  "version": "0.0.5",
  "peerDependencies": {
    "@angular/common": "^7.1.0",
    "@angular/core": "^7.1.0",
    "@ng-bootstrap/ng-bootstrap": "^2.0.0",
    "@fortawesome/angular-fontawesome": "0.1.0-9",
    "@fortawesome/fontawesome-svg-core": "^1.2.0-11",
    "@fortawesome/free-solid-svg-icons": "^5.1.0-8",
    "@fortawesome/free-regular-svg-icons": "^5.1.0-8",
    "@fortawesome/free-brands-svg-icons": "5.1.0-8",
    "bootstrap": "^4.0.0"
  },
  "main": "bundles/candiman-website.umd.js",
  "module": "fesm5/candiman-website.js",
  "es2015": "fesm2015/candiman-website.js",
  "esm5": "esm5/candiman-website.js",
  "esm2015": "esm2015/candiman-website.js",
  "fesm5": "fesm5/candiman-website.js",
  "fesm2015": "fesm2015/candiman-website.js",
  "typings": "candiman-website.d.ts",
  "metadata": "candiman-website.metadata.json",
  "sideEffects": false,
  "dependencies": {
    "tslib": "^1.9.0"
  }
}

请查看您包裹的package.json file (on Unpkg) 了解更多信息。

请参阅下面的示例,了解如何声明包的原理图:

{
  "name": "@candiman/website",
  "version": "0.0.5",
  "peerDependencies": {
    "@angular/common": "^7.1.0",
    "@angular/core": "^7.1.0",
    "@ng-bootstrap/ng-bootstrap": "^2.0.0",
    "@fortawesome/angular-fontawesome": "0.1.0-9",
    "@fortawesome/fontawesome-svg-core": "^1.2.0-11",
    "@fortawesome/free-solid-svg-icons": "^5.1.0-8",
    "@fortawesome/free-regular-svg-icons": "^5.1.0-8",
    "@fortawesome/free-brands-svg-icons": "5.1.0-8",
    "bootstrap": "^4.0.0"
  },
  "schematics": "./path/to/schematics.json",
  "dependencies": {
    "tslib": "^1.9.0"
  }
}

运行ng build project-name --prod时会出现这样的情况:

{
  "name": "@candiman/website",
  "version": "0.0.5",
  "peerDependencies": {
    "@angular/common": "^7.1.0",
    "@angular/core": "^7.1.0",
    "@ng-bootstrap/ng-bootstrap": "^2.0.0",
    "@fortawesome/angular-fontawesome": "0.1.0-9",
    "@fortawesome/fontawesome-svg-core": "^1.2.0-11",
    "@fortawesome/free-solid-svg-icons": "^5.1.0-8",
    "@fortawesome/free-regular-svg-icons": "^5.1.0-8",
    "@fortawesome/free-brands-svg-icons": "5.1.0-8",
    "bootstrap": "^4.0.0"
  },
  "schematics": "./path/to/schematics.json",
  "main": "bundles/candiman-website.umd.js",
  "module": "fesm5/candiman-website.js",
  "es2015": "fesm2015/candiman-website.js",
  "esm5": "esm5/candiman-website.js",
  "esm2015": "esm2015/candiman-website.js",
  "fesm5": "fesm5/candiman-website.js",
  "fesm2015": "fesm2015/candiman-website.js",
  "typings": "candiman-website.d.ts",
  "metadata": "candiman-website.metadata.json",
  "sideEffects": false,
  "dependencies": {
    "tslib": "^1.9.0"
  }
}

【讨论】:

  • 我认为问题是collection.json 没有作为包的一部分发布,因为ng-packeger 不包含 json 文件。不过不确定。
  • 您应该有某种方法可以自动将必要的原理图相关文件复制到您的软件包的 dist 文件夹中,因为 ng-packagr 目前不适合您(尽管目前存在问题关于这个话题:github.com/ng-packagr/ng-packagr/issues/1180)
  • 我认为这不是问题。我的 package.json 包含指向 collection.json 的链接,但 npm 包文件夹中不存在物理 collection.json,因为 ng-packager 不编译/移动 json 文件。请尝试@candiman/website@0.0.5-beta.3
【解决方案2】:

按照此链接中的示例,我遇到了同样的问题。 https://angular.io/guide/schematics-for-libraries#building-your-schematics

库项目根文件夹中的 copy:collection 脚本显示如下: "copy:collection": "cp schematics/collection.json ../../dist/my-lib/schematics/collection.json" 这会创建一个名为 collection.json 的不必要的子文件夹

我将此脚本更改为 "copy:collection": "cp schematics/collection.json ../../dist/my-lib/schematics" 并将 collection.json 文件复制到可以找到它的原理图文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多