[CLI][Schematics] Override Angular Schematics issue - Collection "D" cannot be resolved. - Windows #29559
Labels
area: @angular/cli
freq1: low
Only reported by a handful of users who observe it rarely
severity3: broken
type: bug/fix
Command
generate
Is this a regression?
The previous version in which this bug was not present was
No response
Description
If you try to override standard Angular Schematics with a custom one by the use of schematicCollections option in angular.json file like for instance:
"cli": { "analytics": false, "schematicCollections": [ "./schematics", "@schematics/angular" ] }
And create your custom schematics (index.ts):
`import {
externalSchematic,
Rule,
SchematicContext,
Tree
} from '@angular-devkit/schematics';
import { Schema as ComponentOptions } from '@schematics/angular/component/schema';
export function generateComponent(options: ComponentOptions): Rule {
console.log('Custom schematics for generate component triggered...');
return (_tree: Tree, _context: SchematicContext) => {
return externalSchematic(
"@schematics/angular",
"component",
options
);
};
}`
It will end up with an error message like this one:
Where D refers to the drive letter of the project folder location.
Minimal Reproduction
Please use the attached repo to reproduce the issue:
schematics-test.zip
Run npm install and then try to generate a component using:
ng g c
command.
Exception or Error
Your Environment
Anything else relevant?
The error is caused by parseSchematicInfo method defined in SchematicsCommandModule in file:
@angular\cli\src\command-builder\schematics-command-module.js
Modifying the function as follows:
parseSchematicInfo(schematic) { if (schematic?.includes(':')) { const segments = schematic.split(':'); const [collectionName, schematicName] = [segments.slice(0, -1).join(':'), segments.at(-1)]; return [collectionName, schematicName]; } return [undefined, schematic]; }
Seems to fix the problem.
The issue is also present in v18.
The text was updated successfully, but these errors were encountered: