Search code examples
angular-clidaterangepickeraot

angular prod build giving error for ng2-daterangepicker plugin


I am having problem with ng2-daterangepicker while making prod build.

ERROR NullInjectorError: StaticInjectorError(AppModule)[DaterangepickerComponent -> DaterangepickerConfig]: 
  StaticInjectorError(Platform: core)[DaterangepickerComponent -> DaterangepickerConfig]: 
    NullInjectorError: No provider for DaterangepickerConfig!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (http://localhost:9000/main.1c670d3f26f8f3342a59.js:28824:25)
    at resolveToken (http://localhost:9000/main.1c670d3f26f8f3342a59.js:40016:24)
    at tryResolveToken (http://localhost:9000/main.1c670d3f26f8f3342a59.js:39960:16)
    at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http://localhost:9000/main.1c670d3f26f8f3342a59.js:39862:20)
    at resolveToken (http://localhost:9000/main.1c670d3f26f8f3342a59.js:40016:24)
    at tryResolveToken (http://localhost:9000/main.1c670d3f26f8f3342a59.js:39960:16)
    at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http://localhost:9000/main.1c670d3f26f8f3342a59.js:39862:20)
    at resolveNgModuleDep (http://localhost:9000/main.1c670d3f26f8f3342a59.js:48299:29)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (http://localhost:9000/main.1c670d3f26f8f3342a59.js:48974:16)
    at resolveDep (http://localhost:9000/main.1c670d3f26f8f3342a59.js:49346:45)

Plugin is working in local as well as in dev build, but not working in prod build

Angular details:


    Angular CLI: 8.3.29
    Node: 10.16.0
    OS: win32 x64
    Angular: 8.2.14
    ... animations, common, compiler, compiler-cli, core, forms
    ... language-service, platform-browser, platform-browser-dynamic
    ... router
    
    Package                           Version
    -----------------------------------------------------------
    @angular-devkit/architect         0.803.29
    @angular-devkit/build-angular     0.803.29
    @angular-devkit/build-optimizer   0.803.29
    @angular-devkit/build-webpack     0.803.29
    @angular-devkit/core              8.3.29
    @angular-devkit/schematics        8.3.29
    @angular/cdk                      8.2.3
    @angular/cli                      8.3.29
    @angular/material                 8.2.3
    @ngtools/webpack                  8.3.29
    @schematics/angular               8.3.29
    @schematics/update                0.803.29
    rxjs                              6.4.0
    typescript                        3.5.3
    webpack                           4.39.2

Plugin Link: https://www.npmjs.com/package/ng2-daterangepicker


Solution

  • I had the exact same issue. Fixed it by importing DaterangepickerConfig under providers in the module that declares your Daterangepicker

    EDIT: Also had to add: @import '~ng2-daterangepicker/assets/daterangepicker.css'; to styles .css