Angular2 – Invalid providers for Component – only instances of Provider and Type are allowed

When working with Angular 2 applications, especially large ones with barrels, you might encounter this error :

Invalid providers for MyComponent – only instances of Provider and Type are allowed

Often you will get this error when adding a service in the providers part of the component. Check first if all your service is fine and if it is, let met save you some time and an headache :

Check the order of your import statement – If your service is imported after the component, you will be in trouble

To make it even more clear if you have at some point in your index.ts or any import file

import { ExempleController } from './exemple';
import { ExempleService } from './service';

And you get the error, just change to :

import { ExempleService } from './service';
import { ExempleController } from './exemple';