Using Rollup for Angular 2's AoT compiler and importing Moment.js

后端 未结 9 1774
天涯浪人
天涯浪人 2020-12-24 13:34

I\'m trying to follow the official AoT guide for Angular 2, and I\'m using Moment.js in my application. Moment.js is on my packages.json file, and I\'m using versio

9条回答
  •  清歌不尽
    2020-12-24 13:50

    We had a similar issue with ng-packagr which uses rollup to generate a module that can be published in an npm repo. Our project was built-up using @angular-cli (using webpack).

    We have 2 dependencies that are imported using the asteriks method:

     import * as dataUrl from 'dataurl';
    

    Worked fine, is used like:

     dataUrl.parse(url)
    

    Another import gave the error (Cannot call a namespace) because the exported object is to be used as a function:

     import * as svgPanZoom from 'svg-pan-zoom';
     svgPanZoom(element); <== error: Cannot call a namespace
    

    We could workaround this by assigning the exported initializer function to another const and use that in the code:

     import * as svgPanZoomImport from 'svg-pan-zoom';
     const svgPanZoom = svgPanZoomImport;
    
     svgPanZoom(element);
    

    We also made the tsconfig.json config change as described above.

    Versions: ng-packagr: 1.4.1 rollup: 0.50.0 typescript: 2.3.5 @angular/cli: 1.4.8 webpack: 3.7.1

    Hope this help,

    Rob

提交回复
热议问题