'Angular schematics exception: "NOT SUPPORTED: keyword "id", use "$id" for schema ID"
I have a custom schematic that won't apply to a new project... I also looked at this question but I couldn't make it work...
My main workspace runs with this configuration:
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
And my project with this:
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
Inside my workspace i can make a new project with no problems; then i move inside it and when I run the command ng g project-template-13:project-template-13
(my custom schematic) the following exception is thrown:
[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)
I tried downgrading to angular 12 as said in the question mentioned above, but it doesn't seem to work. Can someone help me with this?
P.s. I'll provide additional information if needed
Solution 1:[1]
I found out that there were 2 typos... The first one in one function of my schematics, the other one in the schema.json where i had "id": "ProjectTemplateSchema"
instead of "$id": "ProjectTemplateSchema"
Solution 2:[2]
try doing ng update on the main workspace cause the issue is probably caused by version mismatch. These packages:
@angular-devkit/core 11.2.18
@angular-devkit/schematics 11.2.18
should become thirteen.
Solution 3:[3]
In case this helps someone else when using nx I had to manually update the angular.json of an existing library build using ng-packagr from "@angular-devkit/build-ng-packagr" to "@nrwl/angular:ng-packagr-lite". Then remove the dependency @angular-devkit/build-ng-packagr from my project.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Federico Andreoli |
Solution 2 | Can Geylan |
Solution 3 | Alvaro Cruz |