Attempting to utilize moment.js with TypeScript 2.1.5 has been a bit of a challenge for me.
I went ahead and installed moment using npm :
npm install moment --save-dev
The d.ts file is already included with moment.js, so no need to install via @typings as usual. However, upon compiling my project, I encountered the following error :
Error TS2307: Cannot find module 'moment'.
To provide some context, here's a simple test case that I created to replicate the issue:
repro.ts file
import * as moment from "moment";
const date = moment().format("YYYY");
console.log(date);
tsconfig.json file :
{
"compilerOptions": {
"module": "amd"
}
}
Upon trying to compile with:
.\node_modules\.bin\tsc
I received the aforementioned error. Interestingly enough, the compilation works fine if I target commonjs module (setting "module": "commonjs" in tsconfig).
What would be the correct approach to use moment when targeting amd module?