Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve all parameters for service #6997

Closed
Yura13 opened this issue Jul 15, 2017 · 5 comments
Closed

Can't resolve all parameters for service #6997

Yura13 opened this issue Jul 15, 2017 · 5 comments

Comments

@Yura13
Copy link

Yura13 commented Jul 15, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

angular 4.2.6
@angular/cli: 1.2.0
node: 6.11.0
os: win32 x64

Repro steps.

core/core.module.ts

import { ApiService, HttpService, SpinnerService } from 'core/services';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [
    SpinnerComponent
  ],
  providers: [
    ApiService,
    HttpService,
    SpinnerService,
  ]
})
export class CoreModule {}

core/services/index.ts

export * from './api.service';
export * from './http.service';
export * from './spinner.service';

core/services/http.service.ts

export class HttpService extends Http {
  constructor(backend: XHRBackend,
              defaultOptions: RequestOptions,
              private spinnerService: SpinnerService) {
    super(backend, defaultOptions);
  }
}

core/services/api.service.ts

export class ApiService {
  constructor(private httpService: HttpService) { }
}

The log given by the failure.

core/services/index.ts

export * from './api.service';
export * from './http.service';
export * from './spinner.service';

Error stack:

Uncaught Error: Can't resolve all parameters for ApiService: (?).
    at syntaxError (compiler.es5.js:1689)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getDependenciesMetadata (compiler.es5.js:15757)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getTypeMetadata (compiler.es5.js:15625)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getInjectableMetadata (compiler.es5.js:15611)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getProviderMetadata (compiler.es5.js:15902)
    at compiler.es5.js:15831
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getProvidersMetadata (compiler.es5.js:15791)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15446)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleSummary (compiler.es5.js:15299)

core/services/index.ts

export * from './http.service';
export * from './api.service';
export * from './spinner.service';

Error stack:

Uncaught Error: Can't resolve all parameters for HttpService: ([object Object], [object Object], ?).
    at syntaxError (compiler.es5.js:1689)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getDependenciesMetadata (compiler.es5.js:15757)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getTypeMetadata (compiler.es5.js:15625)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getInjectableMetadata (compiler.es5.js:15611)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getProviderMetadata (compiler.es5.js:15902)
    at compiler.es5.js:15831
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getProvidersMetadata (compiler.es5.js:15791)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15446)
    at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleSummary (compiler.es5.js:15299)

Mention any other details that might be useful.

When reorder imports in core/services/index.ts everything works

export * from './spinner.service';
export * from './http.service';
export * from './api.service';
@deebloo
Copy link
Contributor

deebloo commented Jul 18, 2017

@Yura13 it sounds like you have a cyclical dependency. 1.3.0-beta has a plugin that will warn you of cyclical deps and show you their path. Would it be possible for you to try updating your project and see what it says?

@Yura13
Copy link
Author

Yura13 commented Jul 18, 2017

@deebloo You are right. Here is present a cyclical dependency related to import from the index file.
In this example: ApiService use HttpService and HttpService use SpinnerService. So it will an error, if ordering in the index file different from below:

export * from './spinner.service';
export * from './http.service';
export * from './api.service';

@filipesilva
Copy link
Contributor

Closing as answered by @deebloo 👍

@Yura13
Copy link
Author

Yura13 commented Jul 28, 2017

I guess this problem related to building process when import from index file.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants