【问题标题】:Angular schematics exception: "NOT SUPPORTED: keyword "id", use "$id" for schema ID"Angular 原理图异常:“不支持:关键字“id”,使用“$id”作为模式 ID”
【发布时间】:2022-05-04 04:23:27
【问题描述】:

我有一个不适用于新项目的自定义原理图...我还查看了this question,但我无法使其工作...

我的主工作区使用以下配置运行:

Angular CLI: 13.2.3
Node: 16.13.0
Package Manager: npm 7.24.2
OS: win32 x64

Angular: 13.2.2
... core

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1302.3 (cli-only)
@angular-devkit/core         11.2.18
@angular-devkit/schematics   11.2.18
@schematics/angular          13.2.3 (cli-only)
@schematics/update           0.1102.18

还有我的项目

Angular CLI: 13.2.3
Node: 16.13.0
Package Manager: npm 7.24.2
OS: win32 x64

Angular: 13.2.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router     

Package                         Version
---------------------------------------------------------  
@angular-devkit/architect       0.1302.3
@angular-devkit/build-angular   13.2.3
@angular-devkit/core            13.2.3
@angular-devkit/schematics      13.2.3
@angular/cli                    13.2.3
@schematics/angular             13.2.3
rxjs                            7.5.4
typescript                      4.5.5

在我的工作空间内,我可以毫无问题地创建一个新项目;然后我在里面移动,当我运行命令ng g project-template-13:project-template-13(我的自定义示意图)时,会引发以下异常:

[error] Error: Collection "project-template-13" cannot be resolved.
at SchematicEngineHost.resolve (C:\Users\user\workspace\my-project\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:75:19)
at SchematicEngineHost._resolveCollectionPath (C:\Users\user\workspace\my-project\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:80:37)
at SchematicEngineHost.createCollectionDescription (C:\Users\user\workspace\my-project\node_modules\@angular-devkit\schematics\tools\file-system-engine-host-base.js:118:27)
at SchematicEngine._createCollectionDescription (C:\Users\user\workspace\my-project\node_modules\@angular-devkit\schematics\src\engine\engine.js:162:40)
at SchematicEngine.createCollection (C:\Users\user\workspace\my-project\node_modules\@angular-devkit\schematics\src\engine\engine.js:155:43)
at GenerateCommand.getCollection (C:\Users\user\workspace\my-project\node_modules\@angular\cli\models\schematic-command.js:143:35)
at GenerateCommand.initialize (C:\Users\user\workspace\my-project\node_modules\@angular\cli\models\schematic-command.js:62:37)
at async GenerateCommand.initialize (C:\Users\user\workspace\my-project\node_modules\@angular\cli\commands\generate-impl.js:20:9)
at async GenerateCommand.validateAndRun (C:\Users\user\workspace\my-project\node_modules\@angular\cli\models\command.js:121:22)
at async runCommand (C:\Users\user\workspace\my-project\node_modules\@angular\cli\models\command-runner.js:224:24)

我尝试降级到 angular 12,如上述问题中所述,但它似乎不起作用。 有人可以帮我解决这个问题吗?

P.s.如果需要,我会提供更多信息

【问题讨论】:

    标签: angular exception angular-cli package.json angular-schematics


    【解决方案1】:

    尝试在主工作区上进行 ng update,因为问题可能是由版本不匹配引起的。这些包:

    @angular-devkit/core         11.2.18
    @angular-devkit/schematics   11.2.18
    

    应该变成十三岁。

    【讨论】:

      【解决方案2】:

      我发现有 2 个拼写错误...第一个是我的原理图函数中的第一个,另一个是 schema.json 中的 "id": "ProjectTemplateSchema" 而不是 "$id": "ProjectTemplateSchema"

      【讨论】:

        【解决方案3】:

        如果在使用 nx 时这对其他人有帮助,我必须使用 ng-packagr 手动将现有库构建的 angular.json 从“@angular-devkit/build-ng-packagr”更新为“@nrwl/angular: ng-packagr-lite”。然后从我的项目中删除依赖项@angular-devkit/build-ng-packagr。

        【讨论】:

          猜你喜欢
          • 2022-01-21
          • 2021-12-30
          • 2021-12-22
          • 1970-01-01
          • 2017-04-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多