Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI][Schematics] Override Angular Schematics issue - Collection "D" cannot be resolved. - Windows #29559

Closed
1 task
sek1973 opened this issue Feb 2, 2025 · 1 comment · Fixed by #29598
Closed
1 task
Assignees
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix

Comments

@sek1973
Copy link

sek1973 commented Feb 2, 2025

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

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:

Collection "D" cannot be resolved.

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

Angular CLI: 19.1.5
Node: 22.13.0
Package Manager: npm 8.6.0
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.5
@angular-devkit/build-angular   19.1.5
@angular-devkit/core            19.1.5
@angular-devkit/schematics      19.1.5
@angular/cli                    19.1.5
@schematics/angular             19.1.5
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

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.

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken area: @angular/cli labels Feb 6, 2025
@santoshyadavdev
Copy link
Contributor

Seems like issue on windows, I tried the code shared on Mac and it worked, I have a windows machine, I will try it tomorrow to see if I can reproduce it

@alan-agius4 alan-agius4 self-assigned this Feb 10, 2025
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Feb 10, 2025
…lection names on Windows

Previously, the logic incorrectly extracted the drive letter as the collection name when the schematic collection was specified as relative on Windows. This fix ensures that relative paths are parsed and resolved correctly, preventing the drive letter from being mistakenly treated as the collection name.

Closes angular#29559
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Feb 10, 2025
…lection names on Windows

Previously, the logic incorrectly extracted the drive letter as the collection name when the schematic collection was specified as relative on Windows. This fix ensures that relative paths are parsed and resolved correctly, preventing the drive letter from being mistakenly treated as the collection name.

Closes angular#29559
alan-agius4 added a commit that referenced this issue Feb 13, 2025
…lection names on Windows

Previously, the logic incorrectly extracted the drive letter as the collection name when the schematic collection was specified as relative on Windows. This fix ensures that relative paths are parsed and resolved correctly, preventing the drive letter from being mistakenly treated as the collection name.

Closes #29559

(cherry picked from commit 8c7c7ac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
3 participants