0

I built a module A and put it into a package via

call npm run build-release
call npm pack dist/

Then I installed it to another Angular module B with

npm install

Module A has a component that I use in module B, this component (in A) injects a router in its constructor and subscribes to router events:

constructor(private router: Router)

I keep getting an error from this component:

BComponent.html:8 ERROR Error: StaticInjectorError(AppModule)[AComponent -> Router]: 
  StaticInjectorError(Platform: core)[AComponent -> Router]: 
    NullInjectorError: No provider for Router!

Do I have to provide the Router of BComponent to AComponent somehow?

Everything works fine for each module itself and also if I just copy AModule into BModule. The error only occurs if I pack AModule and install it via npm in BModule.

Kackao
  • 1,181
  • 3
  • 13
  • 22
  • Did you find a fix for this? I've added Router as a provider in my unit tests, but not working at all. – Brant Jan 05 '20 at 23:00

1 Answers1

1

I think you have made mistake in AppModule file import route in AppModule.

import { Routes, RouterModule } from '@angular/router';

const routes: Routes = []; // Define your route

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
Abhishek
  • 1,742
  • 2
  • 14
  • 25