1

Hi I've written an angular 2 sdk to facilitate access to our backend service. Github

Now I'm testing it on various popular templates and something strange happens with angular2-webpack-starter's template during bundling.

it "looses" or doesn't recognize the @NgModule Decorator and throws

Unexpected value '[object Object]' imported by the module 'AppModule'

Interestingly the sdk works with ng2-admin by akveo, which is build on the angular2-webpack-starter

Below are some commented Code snippets to illustrate my problem

@NgModule({
    providers:SELFBITS_PROVIDERS,
    imports:[HttpModule]
})

export class SelfbitsAngularModule{
    static initializeApp(config:SelfbitsAppConfig):ModuleWithProviders{
        return {
            ngModule:SelfbitsAngularModule,
            providers:[
                { provide: SELFBITS_CONFIG, useValue: config }
            ]
        }
    }
}

this is the custom Module, which initializes and provides the sdk's dependencies. In app.module.ts I then can run

imports: [ // import Angular's modules
    SelfbitsAngularModule.initializeApp(some_config_data)
  ],

I've compared the webpack config files from angular2-webpack-starter and ng2-admin. They are close to identical and nothing in particular pops up.

If I comment out the @NgModule Decorator the same error is shown in ng2-admin, thus my suspicion is that somehow it's not loaded or lost during the bundling process. Also following the error chain suggest the same

  if (importedMeta === null) {
    throw new Error("Unexpected " + _this._getTypeDescriptor(importedType) + " '" + stringify(importedType) + "' imported by the module '" + stringify(moduleType) + "'");
    }

The sdk also works with angular-cli beta15.

Han Che
  • 8,239
  • 19
  • 70
  • 116

0 Answers0