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 serve` works; `ng build -prod` gives ERROR in Error:[…] add a @NgModule annotation

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

Upgraded to Angular 5 then my ng-gauge component stopped working. So I started using ng-packagr; which made ng serve—and my application—work perfectly. Unfortunately ng build -prod doesn’t work anymore. I’ve also tried adding the --preserve-symlinks argument.

How To Reproduce

Add ng-gauge to your dependencies, use it somewhere, now the error is reproduced.

Expected Behaviour

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

Version Information

ng-packagr: v1.5.0
node: v8.9.0
@angular: v5.0.1
rxjs: 5.5.2
zone.js: 0.8.18

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
fourctvcommented, Nov 24, 2017

I came to ng-packagr for the same reasons. Using angular 5.0.3 and it builds the library and publishes it fine. Where I’m having problems is on the app side, where I use my library. It builds fine for testing, ng build, but I cannot build for production ng build --prod --aot, I get loads of errors stating it cannot find components in my library!

Library is at: https://github.com/fourctv/JS44D

The library build shows the following warnings:

Building Angular library
Generating bundle for js44d
Cleaning bundle build directory
Processing assets
Running ngc
Compiling to FESM15
'default' is not exported by 'node_modules/rxjs/add/operator/toPromise.js'
Compiling to FESM5
Compiling to UMD
Minifying UMD bundle
Converting duplicated definition of variable id to assignment [0:3967,33]
Dropping duplicated definition of variable trial [0:4968,16]
Dropping duplicated definition of variable iterator$$2 [0:10891,16]
Side effects in initialization of unused variable _trailingValue [0:23651,53]
Side effects in initialization of unused variable _hasTrailingValue [0:23651,89]
Side effects in initialization of unused variable _trailing [0:23651,131]
Converting duplicated definition of variable i to assignment [0:25525,17]
Side effects in initialization of unused variable document$1 [0:2338,4]
Side effects in initialization of unused variable location [0:2339,4]
Side effects in initialization of unused variable gc [0:2340,4]
Side effects in initialization of unused variable performance [0:2341,4]
Side effects in initialization of unused variable Event [0:2342,4]
Side effects in initialization of unused variable MouseEvent [0:2343,4]
Side effects in initialization of unused variable KeyboardEvent [0:2344,4]
Side effects in initialization of unused variable EventTarget [0:2345,4]
Side effects in initialization of unused variable History [0:2346,4]
Side effects in initialization of unused variable Location [0:2347,4]
Side effects in initialization of unused variable EventListener [0:2348,4]
Side effects in initialization of unused variable rxSubscriber_1 [0:5114,4]
Side effects in initialization of unused variable rxSubscriber_2 [0:5115,4]
Side effects in initialization of unused variable observable_1 [0:5422,4]
Side effects in initialization of unused variable observable_2 [0:5423,4]
Side effects in initialization of unused variable observable_3 [0:5424,4]
Side effects in initialization of unused variable iterator_1 [0:6946,4]
Side effects in initialization of unused variable iterator_2 [0:6947,4]
Side effects in initialization of unused variable iterator_3 [0:6948,4]
Side effects in initialization of unused variable RefCountSubscriber [0:19575,4]
Side effects in initialization of unused variable throttle_2$2 [0:23679,4]
Side effects in initialization of unused variable throttle_3$1 [0:23680,4]
Side effects in initialization of unused variable TestScheduler$1 [0:25938,4]
Side effects in initialization of unused variable animationFrame_1 [0:26314,4]
Side effects in initialization of unused variable throttle$3 [0:26315,4]
Side effects in initialization of unused variable Symbol [0:26329,4]
Remapping source maps
Copying staged files
Writing package metadata
Built Angular bundle for js44d
Built Angular library from /js44D, written to /js44D/dist

And when I use it in my app, and try ng build --prod, I get something like this:

      looking for modules in /Best Flex/BestClientesJS/src
        using description file: /Best Flex/BestClientesJS/package.json (relative path: ./src)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: /Best Flex/BestClientesJS/package.json (relative path: ./src)
          using description file: /Best Flex/BestClientesJS/package.json (relative path: ./src/js44d/src/js44D/index)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Best Flex/BestClientesJS/src/js44d/src/js44D/index doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Best Flex/BestClientesJS/src/js44d/src/js44D/index.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Best Flex/BestClientesJS/src/js44d/src/js44D/index.js doesn't exist
            as directory
              /Best Flex/BestClientesJS/src/js44d/src/js44D/index doesn't exist

repeated a ton of times

FYI, ng serve or ng build work fine and produce perfect builds! oh, and the library also works fine in NativeScript.

Versions:

ng-packagr: v1.6.0
node: v8.9.1
@angular: v5.0.3
rxjs: 5.5.2
zone.js: 0.8.18
typescript: 2.6.1
3reactions
dhergescommented, Nov 10, 2017

Hi, thanks for your report.

I consider this an angular 5 migration task. Is that right?

There will be changes and a new version for angular 5 … “soon” like next week or in two weeks time. I’m asking to be patient for that.

Do you have a GitHub repo or similar with the sources? I am also trying to understand what is not working …

  • is the library no longer compiling with ng@5 peerDeps?
  • can the library be compiled, but the binaries no more be imported into an ng cli app in version5?
  • can binaries with ng@4 peerDeps not be imported into ng cli app with version 5?

Cheers, David

On 10. Nov 2017, at 05:17, Samuel Marks notifications@github.com wrote:

Type of Issue

[x] Bug Report [ ] Feature Request Description

Upgraded to Angular 5 then my ng-gauge component stopped working. So I started using ng-packagr; which made ng serve—and my application—work perfectly. Unfortunately ng build -prod doesn’t work anymore. I’ve also tried adding the --preserve-symlinks argument.

How To Reproduce

Add ng-gauge to your dependencies, use it somewhere, now the error is reproduced.

Expected Behaviour

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

Version Information

ng-packagr: v1.5.0 node: v8.9.0 @angular: v5.0.1 rxjs: 5.5.2 zone.js: 0.8.18 please include any version information that might be relevant, e.g. other third-party libraries

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Angular 5] `ng build --prod` gives error […] add a @NgModule ...
I am using @once/ui shared library in a project. The command ng serve works fine for me and everything works as expected. Unfortunately,...
Read more >
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 >
Deprecated APIs and features - Angular
The downgradeModule supports more ergonomic NgModule-based API (versus NgModule factory based API). Deprecated featureslink. This section lists all deprecated ...
Read more >
Introduction to services and dependency injection - Angular
The @Injectable() decorator defines a class as a service in Angular and allows Angular to inject it into a component as a dependency....
Read more >
NgModule - Angular
A template can use exported declarables from any imported module, including those from modules that are imported indirectly and re-exported. For example, ...
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