Ngx-bootstrap: aot process working in 1.2.6 now failing in 1.3

Created on 28 Jan 2017  路  14Comments  路  Source: valor-software/ngx-bootstrap

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;

question

Most helpful comment

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.

All 14 comments

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()

]
}

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

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

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)

@xclayl please try v1.3.3

@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.

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

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.

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

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';

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

.<

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haisaco picture haisaco  路  3Comments

hugonne picture hugonne  路  3Comments

tpiros picture tpiros  路  3Comments

ctrl-brk picture ctrl-brk  路  3Comments

PascalHonegger picture PascalHonegger  路  3Comments