Angular-cli: Angular6 and CLI 6.0.7 getting build error for some libraries 'Please add a @NgModule annotation'

Created on 12 Jun 2018  路  8Comments  路  Source: angular/angular-cli

- [x] bug report 
- [ ] feature request

### Area

- [x] devkit
- [ ] schematics


### Versions

Angular CLI: 6.0.7
Node: 8.9.4
OS: darwin x64
Angular: 6.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.7
@angular-devkit/build-angular     0.6.7
@angular-devkit/build-optimizer   0.6.7
@angular-devkit/core              0.6.7
@angular-devkit/schematics        0.6.7
@angular/cli                      6.0.7
@ngtools/webpack                  6.0.7
@schematics/angular               0.6.7
@schematics/update                0.6.7
rxjs                              6.2.0
typescript                        2.7.2
webpack                           4.8.3

macOS (High Sierra)



### Repro steps

npm run build
with script:
"build": "ng build --prod --progress false --source-map  true && gulp build",


### The log given by the failure

ERROR in : Unexpected value 'Ng2SmartTableModule ... Please add a @NgModule annotation.



### Desired functionality

Should build.

This is a problem for multiple node libraries:
https://github.com/akveo/ng2-smart-table/pull/801
https://github.com/willsoto/ng-chartist/issues/198

repro steps

Most helpful comment

Issue still exists and not fixed at least in ng-cli 6.0.9. It's easy to reproduce.
But, probably, the case is exotic. But, personally, I'm not sure.

The problem is in classes re-re-export.

_Example:_

The code in some library:

File ~/classes/index.ts:
export * from './my-comp-1.compontent'; export * from './my-comp-2.compontent';

File ~/public_api.ts:
export * from './classes' // we can do it, as TypeScript see the ~/classes/index.ts file ...

If we import libaray to application, then everething works fine with ng serve or with ng build --prod --aot=false --build-optimizer=false, but on build with command ng build --prod we getting reported error.

All 8 comments

This issue only seems to occur when using the --prod flag in the build script.

When I build using --prod and I use --aot=false --build-optimizer=false it builds fine. This error seems to happen due to aot when the build is converting html and typescript files into javascript.

https://angular.io/guide/aot-compiler

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

@filipesilva will do. This is my first bug report on github and I'm swamped at work right now, so it may take me a few days to get to it.

@filipesilva ,

So in the process of making a repo-app, I couldn't get the problem to occur:
akveo/ng2-smart-table#801
version 1.3.3 was giving me this error before, but now it is not. My app builds with
--prod just fine. Go figure...

Sorry for wasting your time. I guess you can close this issue.

Issue still exists and not fixed at least in ng-cli 6.0.9. It's easy to reproduce.
But, probably, the case is exotic. But, personally, I'm not sure.

The problem is in classes re-re-export.

_Example:_

The code in some library:

File ~/classes/index.ts:
export * from './my-comp-1.compontent'; export * from './my-comp-2.compontent';

File ~/public_api.ts:
export * from './classes' // we can do it, as TypeScript see the ~/classes/index.ts file ...

If we import libaray to application, then everething works fine with ng serve or with ng build --prod --aot=false --build-optimizer=false, but on build with command ng build --prod we getting reported error.

@saaivs have you managed to find a solution for this?

@saaivs have you managed to find a solution for this?

Last year we managed it by using the explicit full path to files. But currently, looks like, it works as expected with recent version of angular-cli.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericel picture ericel  路  3Comments

hareeshav picture hareeshav  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments

sysmat picture sysmat  路  3Comments