ng g module with route option not working with the new provideRouter

Open
#24,497 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, typescript
Domain
cli, tooling

Research direction

Reproduce ng g m foo --route=foo -m=app in an Angular 15 project using provideRouter, then inspect the module-generation route handling against app-routing.module.ts and app.module.ts. Done means the command finds the exported routes declaration and generates the module with the requested route without the shown error.

Written by the indexing model from the issue text.

Description

area: @schematics/angular freq1: low severity3: broken type: bug/fix
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

when using the new way provideRouter the command ng g m foo --route=foo -m=app stop working

Minimal Reproduction

create new angular 15 project
in app-routing.module.ts

  1. remove AppRoutingModule
  2. export the routes const

in app.module.ts

  1. remove AppRoutingModule from import array
  2. add provideRouter(routes) to the providers array

then in the command line run ng g m foo --route=foo -m=app

Exception or Error
Couldn't find a route declaration in /src/app/app-routing.module.ts.
Use the '--module' option to specify a different routing module.
Your Environment
Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.5
@angular-devkit/build-angular   15.0.5
@angular-devkit/core            15.0.5
@angular-devkit/schematics      15.0.5
@angular/cli                    15.0.5
@schematics/angular             15.0.5
rxjs                            7.5.7
typescript                      4.8.4
Anything else relevant?

changing the file name from app-routing.module.ts to routes.ts gives a different but similar error message

Couldn't find a route declaration in /src/app/app.module.ts.
Use the '--module' option to specify a different routing module.
Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.