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

后端 未结 9 1724
天涯浪人
天涯浪人 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条回答
  •  萌比男神i
    2020-12-24 14:00

    I have finally managed to get rid of both errors. Indeed to avoid:

    Cannot call a namespace ('moment')

    You need to use:

    import moment from 'moment'

    Then to avoid

    "moment" has no default export

    You have to add into your tsconfig.json (compilerOptions):

    "allowSyntheticDefaultImports": true

    EDIT 17/11/2016

    I also had to add the following to my rollup-config.js file:

    plugins: [
      nodeResolve({jsnext: true, module: true}),
      commonjs({
        include: [
            'node_modules/rxjs/**',
            'node_modules/moment/**'
          ]
        }
      }),
      uglify()
    ]
    

提交回复
热议问题