Mostefai Mohammed Amine's Blog

Say That I Was Here !

No provider for “SER” after Angular 2 Upgrade

 

Certainly, after upgrading Angular 2 to the latest version (starting from RC6), you’ll probably encounter one of the following errors:

· “No provider for service XXX”

· The component “CCC” does not to module “MMM”

A little troubleshooting will indicate that the related files are loaded twice knowing that everything worked just fine before the update.

The clue is that the new version of Angular 2 does take in consideration the difference between lowercase and uppercase later in type script import statements.

Hence, the two following statements:

import {SER} from “./services/ser.service”;

 

and

import {SER} from “./Services/ser.service”;

will be considered as two distinct paths by A2 and will cause the error.

The solution is quite simple, if you have such behavior, just analyze that the required file is not loaded twice and if so, locate the import statements that are different in the case sensitive sense.

Adopt as a best practice writing all your import statement using lowercase letters and centralizing your exports in a file to minimize the import statements.

Loading