angular-cli: Error when using exported interface

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 8.0.3

(See “anything else relevant” section, exact bug has appeared and been fixed before)

Description

A clear and concise description of the problem...

Using an exported interface produces an error, app is not served.

🔬 Minimal Reproduction

export an interface:

export interface AppConfig {..}
export let APP_CONFIG = new InjectionToken<AppConfig>('app.config');

Import it elsewhere: import { APP_CONFIG, AppConfig } from '../app.config'; Use it:

export class MyService {
  constructor(@Inject(APP_CONFIG) config: AppConfig,...
  ...
}

🔥 Exception or Error

ng serve

ERROR in ./src/app/shared/my.service.ts 20:12-21
"export 'AppConfig' was not found in '../app.config'

App is not served. Havent tried build.

🌍 Your Environment

Angular CLI: 8.0.4
Node: 12.4.0
OS: win32 x64
Angular: 8.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.4
@angular-devkit/build-angular     0.800.4
@angular-devkit/build-optimizer   0.800.4
@angular-devkit/build-webpack     0.800.4
@angular-devkit/core              8.0.4
@angular-devkit/schematics        8.0.4
@angular/cli                      8.0.4
@angular/pwa                      0.800.4
@ngtools/webpack                  8.0.4
@schematics/angular               8.0.4
@schematics/update                0.800.4
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant? Had this exact issue almost 3 years ago - https://github.com/angular/angular-cli/issues/2034#issuecomment-246009829. That issue has so many comments that I forget exactly how it was actually resolved, but it was, and warning eventually went away. Now its back. At that time it was a warning and was ignorable. This time its an error and app is not served…

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 31
  • Comments: 18

Commits related to this issue

Most upvoted comments

Same issue here. It seems that the issue was introduced with version 0.800.4 of the @angular-devkit/build-angular as already stated. If I explicitly install version 0.800.3 my application compiles with no error.

For everyone who needs a temporary solution npm install @angular-devkit/build-angular@0.800.3 should fix the problem for now.

It is not just exported interfaces, either. I think it has to do with the @Inject() decorator, because this code has the same problem, where the interface is local to the component.

import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';

interface Dialog {
  title: string;
  content: string;
}

@Component({
  templateUrl: 'dialog.component.html'
})
export class DialogComponent {
  constructor(
    public dialogRef: MatDialogRef<DialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: Dialog
  ) {}

  onNoClick(): void {
    this.dialogRef.close();
  }
}

Mela, I confirm this issue is fixed but now we are being hit by https://github.com/angular/angular-cli/issues/14888 ):

Same here. Explicitly installing build-angular@0.800.3 and @angular-cli version 8.0.3 solves the problem.