valor-software / ngx-bootstrap

Fast and reliable Bootstrap widgets in Angular (supports Ivy engine)
https://valor-software.com/ngx-bootstrap
MIT License
5.53k stars 1.69k forks source link

aot process working in 1.2.6 now failing in 1.3 #1573

Closed budcribar closed 7 years ago

budcribar commented 7 years ago

Fails during the rollup step in the aot process rollup -c rollup-config.js produces

Cannot call a namespace ('moment') node_modules\ng2-bootstrap\datepicker\date-formatter.js (6:15) 4: } 5: DateFormatter.prototype.format = function (date, format) { 6: return moment(date.getTime()).format(format); ^ 7: }; 8: return DateFormatter;

budcribar commented 7 years ago

rollup config:

import rollup from 'rollup' import nodeResolve from 'rollup-plugin-node-resolve' import commonjs from 'rollup-plugin-commonjs'; import uglify from 'rollup-plugin-uglify'

export default { entry: 'app/main.js', dest: 'dist/build.js', // output a single application bundle sourceMap: false, format: 'iife', plugins: [ nodeResolve({jsnext: true, module: true}), commonjs({ include: [

     'node_modules/rxjs/**',
     'node_modules/ng2-truncate/dist/**',
     'node_modules/ng2-bootstrap/**',
     'node_modules/ng2-pagination/**',
     'node_modules/angular2-highcharts/**'
    ],
     namedExports: {
            'node_modules/angular2-highcharts/index.js': ['ChartModule'],
             'node_modules/ng2-pagination/index.js': ['Ng2PaginationModule'],                   
             'node_modules/ng2-truncate/dist/index.js': ['TruncateModule'],

        }

  }),
  uglify()

] }

valorkin commented 7 years ago

it could be fixed with build configuration check comments here: https://github.com/valor-software/ng2-bootstrap/pull/1556

valorkin commented 7 years ago

@budcribar please try a solution from PR if it will not work, please give a note in PR

xclayl commented 7 years ago

I'm had the same issue (rollup js failing). Using version 1.2.6 fixed it for me. Setting "allowSyntheticDefaultImports": true had no impact on my angular2 project (rollup still failed with 1.3.0)

valorkin commented 7 years ago

@xclayl please try v1.3.3

xclayl commented 7 years ago

@valorkin Thanks, but 1.3.3 still fails with the "moment" error when doing the AOT build. I deleted my node_modules folder and ran "npm install" before testing.

valorkin commented 7 years ago

@xclayl does it works with "allowSyntheticDefaultImports": true ?

robdunnwinning commented 7 years ago

This issue still occurs with "allowSyntheticDefaultImports": true.

Changing: import * as moment from 'moment'; to import moment from 'moment';

in /src/datepicker/date-formatter.ts seems to have fixed the problem for me with v1.3.3 however I have not had a look to see if there are any regressions from changing this.

nastakhov commented 7 years ago

Still doesn't work for 1.3.3 Forced to use ng2-bootstrap 1.2.6

"Cannot call a namespace ('moment')" allowSyntheticDefaultImports: true doesn't help

kisdaniel commented 7 years ago

I also have the same issue and downgrading to 1.2.6 not solves my problem it also shows the same error:

node_modules/ng2-bootstrap/datepicker/date-formatter.js (6:15)
4:     }
5:     DateFormatter.prototype.format = function (date, format) {
6:         return moment(date.getTime()).format(format);
                  ^
7:     };
8:     return DateFormatter;

What I can do is change this line in date-formatter.js from import * as moment from 'moment'; to import moment from 'moment';

valorkin commented 7 years ago

For some reason this doesn't work for me: import moment from 'moment';

.<

budcribar commented 7 years ago

I am still having this problem in 3 different projects. Is there a workaround other than reverting back to 1.2.6?

valorkin commented 7 years ago

 I am using angular-cli and AoT works fine, what are you using?

xclayl commented 7 years ago

I haven't tried this yet, but my system.js differs from the recommendation here (angular2 quickstart-based): https://github.com/valor-software/angular2-quickstart/blob/master/README.md