angular: Bad failure mode when missing module import for router destination

Problem

When routing to a component where its NgModule is not imported, the application fails in an unexpected way (that is, it should fail, but in a more expected way). Ultimately this is a case of bad error reporting.

Reproduction

https://github.com/jelbourn/material2-app/tree/router-bad-error

Current behavior

In this production, you will see the error No provider for FocusOriginMonitor!.

The provider is missing because MdCheckbox injects FocusOriginMonitor, but the MdCheckboxModule was never imported anyway (even transitively).

Expected behavior

The error message should be something like “Hey, you defined a route with component “Other” but it’s not in any NgModule imported”.

Overall the very strange thing here is that even though the Other component here is never imported anywhere into the bootstrapped module, the application will currently work so long as there are no missing providers, which is quite unexpected.

Versions

@angular/cli: 1.0.6
node: 6.9.0
os: linux x64
@angular/animations: 4.2.0
@angular/common: 4.2.0
@angular/compiler: 4.2.0
@angular/core: 4.2.0
@angular/forms: 4.1.3
@angular/http: 4.2.0
@angular/material: 2.0.0-beta.6
@angular/platform-browser: 4.2.0
@angular/platform-browser-dynamic: 4.2.0
@angular/platform-server: 4.2.0
@angular/router: 4.2.0
@angular/tsc-wrapped: 4.2.0
@angular/cli: 1.0.6
@angular/compiler-cli: 4.2.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (17 by maintainers)

Most upvoted comments

@vicb I know it’s unlikely, but any chance this could get attention? It’s by far the most common issue I see people get stuck on in Google.