question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Angular 5] `ng build --prod` gives error […] add a @NgModule annotation

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

I want to use 3 level scope in my project like @once/ui/datepicker or @once/ui/dropdown. So I started using ng-packagr; which is working fine for me. I am able to use 3-level scope in my project.

I am using @once/ui shared library in a project. The command ng serve works fine for me and everything works as expected.

Unfortunately, in the project using @once/ui components, ng build -prod doesn’t work anymore. I’ve also tried adding the --preserve-symlinks argument. but no luck!

How To Reproduce

Install @once/ui/datepicker in your project and run ng build --prod, now the error is reproduced. Also adding small code snippet here:

import { DatepickerModule } from '@once/ui/datepicker';
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    DatepickerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

Now run:

ng build --prod

You will get:-

ERROR in : Unexpected value 'DatepickerModule in /install-pack/node_modules/@once/ui/datepicker/src/datepicker.module.d.ts' imported by the module 'AppModule in /install-pack/src/app/app.module.ts'. Please add a @NgModule annotation.

However, if I set --aot to false using:-

ng build --prod --aot false

Everything works and the build is successfull!

Expected Behaviour

ng build -prod should produce compiled minified distribution files like it did with Angular 4.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 2.4.5
@angular/*: 5.2.10
typescript: 2.5.3
node: 9.10.1
npm: 6.0.0```

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
frankyaorenjiecommented, Jun 4, 2019

May I ask is there any update here? We also encountered this issue in Angular7.

6reactions
rocifiercommented, Feb 4, 2020

I just tried to create a new library with angular 8.2 and when I import it into my blank project’s module via the dist folder or the src folder, and build my project with --aot, I get the same type of error. I create a separate workspace for the library than my project, but was careful to match typescript and angular/angular cli versions. Does this mean angular libraries are broken out of the box?

ERROR in : Unexpected value 'UoaControlsModule in C:/Repos/uoa-common/projects/uoa-controls/src/lib/uoa-controls.module.ts' imported by the module 'AppModule in C:/Repos/one-page-app/src/app/app.module.ts'. Please add a @NgModule annotation.

The error must be wrong, because I definitely have the default @NgModule annotation which is exporting the default component (there are no index files). If I build without --aot then it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular error: Please add a @NgModule annotation
You're trying to "import" a component in SomeModule . imports: [ CommonModule, SomeComponent ],. You import modules and declare components, ...
Read more >
Ahead-of-time (AOT) compilation - Angular
When you run the ng build (build only) or ng serve (build and serve locally) CLI commands, the type of compilation (JIT or...
Read more >
Problem building poject with angular library. ng serve works ...
[Solved]-Problem building poject with angular library. ng serve works fine locally Error message is Please add a @NgModule annotation-angular.js.
Read more >
Angular Noob here - what does "Please add a @NgModule ...
Just a quick note: always check for dependencies when upgrading. In my experience, the error you got means, you haven't added a component...
Read more >
Angular Modules and NgModule - Complete Guide
What does an Angular Module look like? · the @NgModule annotation is what actually defines the module · we can list the components,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found