Search code examples
angularjsnlog

Angular: "ng build -prod" produces error for jsnlog


I get the following error if I try to execute ng build --prod:

ERROR in ./src/$$_gendir/app/app.module.ngfactory.ts
Module not found: Error: Can't resolve 'jsnlog/Definitions/jl' in 'C:\xxx\src\$$_gendir\app'
 @ ./src/$$_gendir/app/app.module.ngfactory.ts 31:0-45
 @ ./src/main.ts
 @ multi ./src/main.ts

This error happens only when i run ng build --prod and works fine when i run ng build without any parameters,


Solution

  • I faced this same issue. The problem is that this library is NOT angular AOT compilation ready because it is missing metadata.json file. That is why production build fails and dev build works.

    Instead of registering it to angular service injector, you can directly import it into your error handler service and use it. It makes testing little harder though.

    In your service which extends angular ErrorHandler:

    import { JL } from 'jsnlog';
    

    and in handleError method, do:

    JL().fatalException('Exception', error);