Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#24,497 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
angular, typescript
Ambito
cli, tooling

Direzione di ricerca

Riproduci ng g m foo --route=foo -m=app in un progetto Angular 15 usando provideRouter, quindi esamina la gestione delle route nella generazione del modulo rispetto a app-routing.module.ts e app.module.ts. Il lavoro è completato quando il comando trova la dichiarazione delle route esportata e genera il modulo con la route richiesta senza l'errore mostrato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
27k
Fork
11.8k
Merge medio
17h 25m
PR unite (30g)
183

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di angular/angular-cli

Tutte le issue di angular/angular-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.