Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Service Dependency Injection doesn't work always with version 0.0.39 #325

Closed
savanvadalia opened this issue Nov 8, 2016 · 6 comments
Closed

Comments

@savanvadalia
Copy link

savanvadalia commented Nov 8, 2016

Short description of the problem:

Service dependency injection doesn't work always with version 0.0.39 (default is webpack with this version), however same code without any changes works fine for version 0.0.36 (default is roll-up with this version).
I am using Angular 2 barrels to organise my imports. Upon digging up the problem found that the service getting failed worked fine if I import it as direct file reference.

What behaviour are you expecting?

Service dependency injection should work regardless of webpack, rollup or barrels being used or not.

Steps to reproduce:

  1. Privately Emailed @danbucholtz the sample code.
  2. run npm install on the project and doing ionic serve should give this error in the console
Uncaught Error: Can't resolve all parameters for LoginComponent: (App, NavController, MenuController, ?, Events, LocalStorageService, ErrorParserService).(…)
  1. May be a Barrel related issue: Error will go away if you change the import statement in LoginComponent
    import { LoginService } from '../../account';
    TO
    import { LoginService } from '../../account/login/login.service';
    OR
    import { LoginService } from './login.service';
  2. May be a webpack related issue: Error on Step 2 will also go away if you downgrade ionic-app-scripts version to 0.0.36. To verify theory undo the code changes on Step-3 and downgrade the version to 0.0.36.

Sample Code

import { NavController, MenuController, App, Events } from 'ionic-angular';
import { Component } from '@angular/core';

import { LoginService } from '../../account';
import { UserRegistrationComponent } from '../../account/user-registration';
import { DevicesTabComponent } from '../../shared/navigation';
import { LocalStorageService } from '../../shared/storage';
import { LoginResponse } from '../../shared/contracts';
import { ErrorType } from '../../shared/constants';
import { ErrorParserService } from '../../shared/services';

@Component({
    templateUrl: 'login.component.html'
})
export class LoginComponent {

    public email: string;
    public passWord: string;

    public loginResponse: LoginResponse;

    constructor(public app: App, public nav: NavController, public menu: MenuController,
        public loginService: LoginService, public events: Events,
        public localStorageService: LocalStorageService,
        public errorParserService: ErrorParserService) {

        this.loginResponse = new LoginResponse();
    }

Which @ionic/app-scripts version are you using?
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.2
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
Ionic App Scripts Version: 0.0.39
OS: Windows 7 SP1
Node Version: v6.9.1

@ramonornela
Copy link

ramonornela commented Nov 8, 2016

I have a problem force bundler rollup, Even at 0.0.40

@danbucholtz
Copy link
Contributor

@savanvadalia,

If you run ionic serve does it work correctly? It only errors out on device, right? This seems to be an ngc error. Please let me know so we can address the situation.

Thanks,
Dan

@savanvadalia
Copy link
Author

savanvadalia commented Nov 10, 2016

@danbucholtz

No, it fails on ionic serve itself.

Thanks
Savan

@savanvadalia
Copy link
Author

@danbucholtz Also I updated to latest ionic-app-scripts to latest version 0.0.42 and the same issue still persists.

On a side note new build error reporting looks great 👏 👏 👏

First of all I was expecting my error to be reported and for sec thought why its not working.
But realised this particular error is a run-time error and not compile time and hence it doesn't show up,

Thanks
Savan

@savanvadalia
Copy link
Author

@danbucholtz Any updates on this?

Problem still persist in 0.0.44with webpack.
Switching back to rollup
OR
importing the file with complete path still works fine with webpack.

I hope we some sort of fix for this as I have used barrels heavily in my project.

@jgw96
Copy link
Contributor

jgw96 commented Nov 18, 2016

Hello all! I am going to close this issue as a duplicate of #315. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants