You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Error
An exception is thrown during the method createCollection(), when the collectionName contains a @<version>, e.g. ng add @my/[email protected].
Negative consequences
The consequence is that the custom schematics' schema is not applied for parsing, i.e. the method addSchemaOptionsToCommand() is skipped, becasue of the thrown exception
And btw. the later this exception is ignored here.
Why it happens (internal Angular CLI code)
The error happens becasue eventually this line throws an error, becasue there is no such a directory like node_modules/@my/[email protected], but only node_modules/@my/lib
Because an error is thrown, a custom schema.json is not applied for parsing the arguments then.
Idea of a fix:
Before passing the collectionName as an argument to the createCollection() method, we could first extract any versions from it, e.g. by passing it through npa from 'npm-package-arg', e.g.:
❌ ng add @my/lib@ (with just @) - also causes error
✅ ng add @my/lib (nothing after the package's name) - doesn't cause error
Minimal Reproduction
Create a fresh angular 17 app
In VSCode add a console.error({error}) in the AngularCLI's file node_modules/@angular/cli/src/commands/add/cli.js in line 80 (inside this catch block):
Command
add
Is this a regression?
The previous version in which this bug was not present was
No response
Description
Error
An exception is thrown during the method createCollection(), when the
collectionNamecontains a@<version>, e.g.ng add @my/[email protected].Negative consequences
The consequence is that the custom schematics' schema is not applied for parsing, i.e. the method addSchemaOptionsToCommand() is skipped, becasue of the thrown exception
And btw. the later this exception is ignored here.
Why it happens (internal Angular CLI code)
The error happens becasue eventually this line throws an error, becasue there is no such a directory like
node_modules/@my/[email protected], but onlynode_modules/@my/libBecause an error is thrown, a custom schema.json is not applied for parsing the arguments then.
Idea of a fix:
Before passing the
collectionNameas an argument to thecreateCollection()method, we could first extract any versions from it, e.g. by passing it throughnpa from 'npm-package-arg', e.g.:Additional notes
ng add @my/[email protected]- causes errorng add @my/lib@(with just@) - also causes errorng add @my/lib(nothing after the package's name) - doesn't cause errorMinimal Reproduction
Create a fresh angular 17 app
In VSCode add a
console.error({error})in the AngularCLI's filenode_modules/@angular/cli/src/commands/add/cli.jsin line 80 (inside thiscatchblock):angular-cli/packages/angular/cli/src/commands/add/cli.ts
Lines 102 to 106 in ea843eb
see example:
(run
npm install @my/lib- to mitigate the bug Schematic with multi select x-promt errors when using command line parameter: 'path ".foo" should be array' #16320 - but ideally this step shouldn't be needed when this other bug is fixed)run
ng add @my/library@<with-version-here>See an error in the console
error: CollectionCannotBeResolvedException [Error]: Collection "@my/[email protected]" cannot be resolved.Your Environment
Anything else relevant?
No response