Search code examples
angularangular2-routingangular2-meteor

Uncaught Invalid provider - only instances of Provider and Type are allowed, got: [object Object]


After installing my app on another machine, I do reach an error on browser side:

Uncaught Invalid provider - only instances of Provider and Type are allowed, got: [object Object]

This seems to be linked to a wrong bootstrapping of the provider. But nothing seems wrong. Any idea what's wrong ?

Packages

"@angular/common": "^2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/forms": "^0.2.0",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "^3.0.0-beta.2",
"angular2-meteor": "^0.6.2",
"angular2-meteor-auto-bootstrap": "^0.6.0",
"angular2-meteor-polyfills": "^0.1.1",
"angular2-pagination": "^0.2.1",
"core-js": "^2.4.0",
"es6-shim": "^0.35.1",
"hammerjs": "^2.0.8",
"jquery": "^3.0.0",
"meteor-node-stubs": "~0.2.0",
"reflect-metadata": "0.1.2",
"route-matcher": "^0.1.0",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12"

Code

import 'reflect-metadata';
import 'zone.js/dist/zone';
import { bootstrap } from 'angular2-meteor-auto-bootstrap';
import { Component, provide, PLATFORM_DIRECTIVES } from '@angular/core';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import { APP_BASE_HREF } from '@angular/common';
import { provideRouter, RouterConfig, Routes, ROUTER_DIRECTIVES } from '@angular/router';

import { Home } from '../imports/business/home';

export const routes: Routes = [{ path: '',  component: Home, data: {prettyName: 'Accueil'} }];

@Component({
  moduleId: module.id,
  selector: 'app',
  template: require('./app.html').default,
  directives: [ROUTER_DIRECTIVES],
})class App{}


bootstrap(App, [
  disableDeprecatedForms(),
  provideForms(),
  provideRouter(routes),
  provide(PLATFORM_DIRECTIVES, { useValue: [ROUTER_DIRECTIVES], multi: true })
]);

PS: that is not the exact same version, but the exception is thrown here https://github.com/vicb/angular/blob/b8450fa68f704f5f7f0f119034f5e4242664b172/modules/angular2/src/core/di/provider.ts#L567

EDIT This is apparently linked to "@angular/router" and "angular2-meteor-auto-bootstrap" versions that I updated. They had some dependencies to rc.5 and apparently this version change is not backward compatible for my app.

If anyone has an explanation...


Solution

  • I was experiencing the same issue and rolled back to @angular/router-3.0.0-beta.2 (after upgrading to rc.1), deleting the folder at node_modules/@angular/router and installing beta.2, without changing other packages and removed the error and was back in business. After taking a look at: Angular Router Developer Documentation and noting the substantial differences, as well as the change log on the angular/modules/@angular/router github repo, there were substantial changes and rolling back was the quickest fix. My package.json and app.component.ts/main.ts are substantially similar. I have been following this thread as well: Bootstrapping Process for RC5 and have made some preliminary attempts to update things to the new structure, but not made much headway yet. Not sure if this helps as your packages indicate the same @angular/router version.

    Packages:

       "@angular/common": "^2.0.0-rc.4",
        "@angular/compiler": "^2.0.0-rc.4",
        "@angular/core": "^2.0.0-rc.4",
        "@angular/forms": "^0.3.0",
        "@angular/platform-browser": "^2.0.0-rc.4",
        "@angular/platform-browser-dynamic": "^2.0.0-rc.4",
        "@angular/router": "^3.0.0-beta.2",
        "@angular2-material/button": "^2.0.0-alpha.7-2",
        "@angular2-material/card": "^2.0.0-alpha.7-2",
        "@angular2-material/core": "^2.0.0-alpha.7-2",
        "@ngrx/core": "^1.0.1",
        "@ngrx/router": "^1.0.0-beta.2",
        "adm-zip": "^0.4.7",
        "angular2-blaze-template": "^0.0.1",
        "angular2-file-drop": "^0.0.3",
        "angular2-meteor": "^0.6.2",
        "angular2-meteor-auto-bootstrap": "^0.6.0",
        "angular2-meteor-polyfills": "^0.1.1",
        "angular2-notifications": "^0.2.6",
        "es6-shim": "^0.35.1",
        "meteor-node-stubs": "^0.2.3",
        "moment": "^2.14.1",
        "ng2-uploader": "^0.5.10",
        "reflect-metadata": "^0.1.8",
        "rxjs": "^5.0.0-beta.11",
        "superagent": "^2.1.0",
        "typings": "^1.3.2",
        "zone.js": "^0.6.12"
    

    Code:

    'use-strict';
    import 'reflect-metadata';
    import { Component, provide } from '@angular/core';
    import { APP_BASE_HREF } from '@angular/common';
    import { bootstrap } from 'angular2-meteor-auto-bootstrap';
    import {disableDeprecatedForms, provideForms} from '@angular/forms';
    import { provideRouter, RouterConfig, ROUTER_DIRECTIVES } from '@angular/router';
    import { LoginButtons } from './imports/accounts-ui/login-buttons';
    import { APP_ROUTER_PROVIDERS, authProvider } from './app.routes';
    
    
    
    
    import template from './app.html';
    
    @Component({
      selector: 'app',
      template,
      directives: [ROUTER_DIRECTIVES, LoginButtons]
    })
    
    
    
    export class Socially {
    }
    bootstrap(Socially, [APP_ROUTER_PROVIDERS, authProvider, provide(APP_BASE_HREF, { useValue: '/' })]);