0

I have looked at every issue I can find that has a reference to the error I'm having when trying to package my Angular component library. The error is:

BUILD ERROR
Cannot call a namespace ('moment')
Error: Cannot call a namespace ('moment')
... //Rest of stack trace

I have tried adding the "allowSyntheticDefaultImports": true, attribute to my tsconfig.json file, and the "target" is es6. I tried adding a rollup.config.js file, and have tried the following ways of importing moment:

import * as moment from 'moment';

and

import moment from 'moment';

and

import * as momentLib from 'moment';
const moment = momentLib;

and

import moment from 'moment-es6';

None of those worked. But I still get the above error, or that there is no default export for moment.

Does anyone have any tips on how to get this to work?

pjlamb12
  • 2,300
  • 2
  • 32
  • 64

1 Answers1

0

I also tried all the solutions that you also tried, but what worked for me was

import moment from 'moment-with-locales-es6';

and I added to dependencies in package.json

"moment-with-locales-es6": "latest"
Adrian Ber
  • 20,474
  • 12
  • 67
  • 117