Description
I'm using Moment 2.17.1 with TypeScript 2.1.1, OS X (10.11.6) and Node 6.3.0. I'm having trouble importing moment consistently.
In our dev and prod environments, we use Babel to compile. In that scenario, this import statement works:
import moment from 'moment';
This works in the browser but causes TypeError: moment_1.default is not a function
in my mocha tests.
Our test code is built without babel, just tsc
to an output directory and we run from there. In that case, we have to use this statement:
import * as moment from 'moment';
This makes node happy but brings back the dreaded moment is not a function(…)
error when that code is hit in the browser.
Naturally, I need to find one import to rule them all if I want to test any code that uses moment.
I have enabled allowSyntheticDefaultImports
in both environments' tsconfigs. My guess is that the presence of Babel is complicating things but I don't know what the solution is. Would love some advice. Thank you!