1
votes

I upgraded my Angular2 project which was working fine from Beta .21 to beta .25.5. I have fixed all error so that there are no errors when using AOT or non-AOT (e.g. ng serve)

I now get this error on many of my services at runtime when the browser loads and it affects ALL the parameter services for that file.

Can't resolve all parameters for *servicename*: (?)     

First I deleted the barrel I was using and checked circular dependancies.

I then moved them all into the Providers array in App.module and checked that all services have @Injectable(). the only way to get rid of the error was to use the Inject() method, eg:

import { Injectable, Optional, SkipSelf, Inject } from '@angular/core';
import { Subject } from 'rxjs/Subject';

export interface SpinnerState {
    show: boolean;
}

@Injectable()
export class SpinnerService {
    private spinnerSubject = new Subject<SpinnerState>();

    spinnerState = this.spinnerSubject.asObservable();

    constructor( @Optional() @SkipSelf() @Inject(SpinnerService) prior: SpinnerService) {

This fixed the errors but then I got this error on a 3rd party library. How can I debug this to work out the root cause of the problem?

Thanks

"nativeError : Error: Can't resolve all parameters for Logger: (?). at SyntaxError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:134335:27) [<r"

This is how my App.Module looks:

 providers: [
        {
            provide: AuthHttp,
            useFactory: authHttpServiceFactory,
            deps: [Http, RequestOptions],
        },
        [Logger],
        LoggerService,
        SpinnerService,
        DataBreezeService,
        ProfileService,
        AuthService,
        AuthGuardService,
        CanDeactivateGuardService,

I also have these set:

{
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true
}

(as mentioned, my project was working fine before the upgrade - I can't see anything obvious in the release notes).

UPDATE I kept commenting out services with issues and removing params from constructors and each time it just moves to the next service - ie. there is something wrong at a higher level here. Now I am also getting 404 errors on components too, eg.

enter image description here

I don't understand why - for example, the 404 Subscribe component is really simple: I even tried adding "moduleId: 'module.id', " but that made no difference:

import { Component } from '@angular/core';

@Component({
    selector: 'app-subscribe',
    templateUrl: './subscribe.component.html',
    styleUrls: ['./subscribe.component.scss']
})
export class SubscribeComponent {

    constructor() { }
}

GET http://localhost:4200/subscribe.component.html 404 (Not Found)

1
How does the constructor for Logger look like? - Günter Zöchbauer
Why did you wrap Logger with an array [Logger],? - should work fine, just curious - Günter Zöchbauer
WRT the last question - that was just an oversight - I changed that. - Rodney
WRT the Logger library - I just commented it out completely - now it moves to the next class with the same error - ie. there is something really wrong here at a higher level - it is not a particular class or service error I don't think. - Rodney
Ok, I managed to sort this out (12 hours later). I still don't know what caused it, but all the above was a red-herring - I rolled back all my changes in the end. I pinned some exact versions of Angular and other libraries in my packages.json and deleted the node folder and reinstalled. It then seemed to work... very frustrating but at least it is now working in AOT... thanks for the help - Rodney

1 Answers

0
votes

got it up and running by removing all barrel imports and going up to beta 28.3

npm uninstall -g angular-cli
npm cache clean
npm install -g [email protected]

and also update to 28.3 locally in project folder (update angular-cli.json & package.json).