When working with the moment-timezone
module, one issue that arises is receiving a warning if it is included multiple times. In my specific case, I have a module that necessitates the use of this timezone functionality. Since I am unsure whether or not the user will manually set the timezone themselves, my approach is as follows:
if (moment.tz === undefined) {
require('moment-timezone');
moment.tz.setDefault('America/Los_Angeles');
}
While this solution works seamlessly in standard JavaScript, I recently encountered an obstacle when transitioning to TypeScript. The error message produced states: Cannot find name 'require'
.
I attempted to address this by adjusting the line to read
import momentTimezone = require('moment-timezone');
, but then confronted another error: An import declaration can only be used in a namespace or module.
How should I proceed in resolving this dilemma?