Skip to content

AOT build breaks with InjectionToken used cross library boundaries #8097

@CarstenLeue

Description

@CarstenLeue

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I get the following error when using "ng build --prod"

ERROR in Error: Internal error: unknown identifier undefined
    at Object.importExpr$$1 [as importExpr] (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:24097:23)
    at tokenExpr (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:18447:39)
    at providerDef (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:18349:20)
    at C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:18574:77
    at Array.map (<anonymous>)
    at NgModuleCompiler.compile (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:18574:44)
    at AotCompiler._compileModule (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:24030:32)
    at C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:23942:66
    at Array.forEach (<anonymous>)
    at AotCompiler._compileImplFile (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:23942:19)
    at C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:23855:87
    at Array.map (<anonymous>)
    at AotCompiler.emitAllImpls (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler\bundles\compiler.umd.js:23855:52)
    at CodeGenerator.emit (C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler-cli\src\codegen.js:42:46)
    at C:\d\ContentHub\samples-wch-sdk\navigation\node_modules\@angular\compiler-cli\src\codegen.js:33:61
    at <anonymous>

As far as I can tell, the undefined identifier is the value of the provider field in a ClassProvider. Doing a console log for the AST node yields the following result:

providerAST {"token":{"identifier":{"reference":{"filePath":"C:/d/ContentHub/samples-wch-sdk/navigation/node_modules/@angular/common/common.d.ts","name":"NgLocalization","members":[]}}}
,"multiProvider":false,"eager":false,"providers":[{"token":{"identifier":{"reference":{"filePath":"C:/d/ContentHub/samples-wch-sdk/navigation/node_modules/@angular/common/common.d.ts","
name":"NgLocalization","members":[]}}},"useClass":{"reference":{"filePath":"C:/d/ContentHub/samples-wch-sdk/navigation/node_modules/@angular/common/common.d.ts","name":"NgLocaleLocaliza
tion","members":[]},"diDeps":[{"isAttribute":false,"isHost":false,"isSelf":false,"isSkipSelf":false,"isOptional":false,"token":{"identifier":{"reference":{"filePath":"C:/d/ContentHub/sa
mples-wch-sdk/navigation/node_modules/@angular/core/core.d.ts","name":"LOCALE_ID","members":[]}}}}],"lifecycleHooks":[]},"useFactory":null,"deps":[{"isAttribute":false,"isHost":false,"i
sSelf":false,"isSkipSelf":false,"isOptional":false,"token":{"identifier":{"reference":{"filePath":"C:/d/ContentHub/samples-wch-sdk/navigation/node_modules/@angular/core/core.d.ts","name
":"LOCALE_ID","members":[]}}}}],"multi":false}],"providerType":0,"lifecycleHooks":[],"sourceSpan":{"start":{"file":{"content":"","url":"in NgModule WchNgLoggingModule in C:/d/ContentHub
/samples-wch-sdk/navigation/node_modules/ibm-wch-sdk-ng-logger/ibm-wch-sdk-ng-logger.d.ts"},"offset":-1,"line":-1,"col":-1},"end":{"file":{"content":"","url":"in NgModule WchNgLoggingMo
dule in C:/d/ContentHub/samples-wch-sdk/navigation/node_modules/ibm-wch-sdk-ng-logger/ibm-wch-sdk-ng-logger.d.ts"},"offset":-1,"line":-1,"col":-1},"details":null}}
providerAST {"token":{"identifier":{}},"multiProvider":false,"eager":false,"providers":[{"token":{"identifier":{}},"useClass":{"reference":{"filePath":"C:/d/ContentHub/samples-wch-sdk/n
avigation/node_modules/ibm-wch-sdk-ng-logger/ibm-wch-sdk-ng-logger.d.ts","name":"ɵb","members":[],"test":"Carsten"},"diDeps":[],"lifecycleHooks":[]},"useFactory":null,"deps":[],"multi":
false}],"providerType":0,"lifecycleHooks":[],"sourceSpan":{"start":{"file":{"content":"","url":"in NgModule WchNgLoggingModule in C:/d/ContentHub/samples-wch-sdk/navigation/node_modules
/ibm-wch-sdk-ng-logger/ibm-wch-sdk-ng-logger.d.ts"},"offset":-1,"line":-1,"col":-1},"end":{"file":{"content":"","url":"in NgModule WchNgLoggingModule in C:/d/ContentHub/samples-wch-sdk/
navigation/node_modules/ibm-wch-sdk-ng-logger/ibm-wch-sdk-ng-logger.d.ts"},"offset":-1,"line":-1,"col":-1},"details":null}}
tokenMeta {"identifier":{}} {"statements":[],"genFilePath":"C:/d/ContentHub/samples-wch-sdk/navigation/node_modules/ibm-wch-sdk-ng-logger/ibm-wch-sdk-ng-logger.ngfactory.ts"}```

The scenario is this:

  • I have an ng4 CLI application using the standard CLI build
  • this application uses two libraries A and B, both ng4 libraries built against the ng4 module spec
  • A defines an InjectionToken that allows to inject services
  • B provides a service using the Injection token provided by A
    B'm module looks like this (in TS)
// the provider
export const PROVIDER: InjectionToken<LoggerFactory> = WchLoggerFactory;

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [
  ],
  providers: [{ provide: PROVIDER, useClass: Ng2LoggerFactory }],
  exports: [
  ],
  entryComponents: [
  ]
})
export class WchNgLoggingModule {

Where 'WchLoggerFactory' is imported from A.

The problem only occurs if I use modules, if I build everything in one large monolithic application, the build works.

Expected behavior

I expect that InjectionTokens can be used across library boundaries to provide services.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular CLI version: 1.4.7
 
For Tooling issues:
- Node version: v8.6.0
- Platform:  Windows 7

Others:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions