Moment.js + TypeScript. Cannot find name moment

cannot find name 'moment angular 8
cannot find module 'moment
error ts2304: cannot find name
cannot find module '@angular/material-moment-adapter
cannot find name 'moment ts
typescript moment
cannot find name moment dateadapter
cannot find name take

I develope web application with knockout in VisualStudio. I just installed knockout via bower, included d.ts file in project, included script to html page and now i can get access to ko.

Now i try to use moment.js. Like with knockout: install, include d.ts, include script to page and i get an error cannot find name 'moment'. Adding reference to d.ts does not help, import * as moment from 'moment' get an error can not find module moment.

I know that it's a stupid problem, but i can't fix it. What am i doing wrong?

What I'd recommend is using some tool for managing your definitions. Some popular options (you don't need both, just pick one):

  1. tsd - npm i -g tsd
  2. typings - npm i -g typings

These work in a similar fashion as package managers. You can install your definitions like npm/bower installs your dependencies.

Once you have one of these installed, go to your project and install moment + its definition

npm install moment --save

And one of these:

tsd install moment --save
typings install moment --save --ambient

Both of these will create a folder with your definitions in it (both call it typings), and both have an "umbrella" definition file in it, which you should reference in the entry point of your application (first is for tsd, second for typings):

/// <reference path="typings/tsd.d.ts" />
/// <reference path="typings/index.d.ts" />

After this is done, you can use moment (or any other module) as you would:

import * as moment from 'moment'
moment.isDate("I'm not a date")

I suggest checking out these:

Moment.js + TypeScript. Cannot find name moment, What I'd recommend is using some tool for managing your definitions. Some popular options (you don't need both, just pick one):. tsd - npm i -g  $ echo ' import * as moment from "moment"; const now = moment(); ' > test2.ts $ tsc --module commonjs test2.js Unfortunately, my project does not use a bundler or module system, so I'm stuck with "module": "none" for now.

In my case, finally get this error solved by doing the following:

  1. Adding this option "allowSyntheticDefaultImports": true, in the compilerOptions section of the tsconfig.json file (EDITED: As the moment doc. sais in the Note: If you have trouble importing moment, try add "allowSyntheticDefaultImports": true in compilerOptions in your tsconfig.json file.)
  2. Also add "moduleResolution": "node" in the same compilerOptions section. (Found this option looking around the web)
  3. Importing moment module like this import * as moment from 'moment';

Using Moment with Angular and TypeScript, ts(6,30): error TS2304: Cannot find name 'moment'. Try using a /// compiler directive. To fix this, I tried adding the following /// compiler directive: Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

This seems to solve the problem for me (the other solutions in this thread didn't work):

import * as moment from 'moment/moment.js';

I still seem to be getting the correct typescript definitions even referencing the js file directly. I suspect the reason is that the 'moment' folder under node_modules does not have an index.js file but I'm not a typescript typings/compiler expert.

[TypeScript] "error TS2304: Cannot find name 'moment'", Ask questions[TypeScript] "error TS2304: Cannot find name 'moment'" when used with "module":"none". Typescript seems to not be able to resolve the global  Hi everybody, Iam new in using Typescript and angular. First of all i want to use moment.js and jquery i made a reference path in my bootstrap.v3.datetimepicker.d.ts and in my personal ts file. Linked to jquery and moment, and included t

Try adding the below code, it worked for me

import * as MomentD from "node_modules/moment/moment.d";

angular-moment, angular-moment. AngularJS directive and filters for Moment.JS. able to use it unless you override moment using Angular's dependency injection See Resolved Issue timezone: 'Name of Timezone' // e.g. 'Europe/London'. As of version 2.13.0, Moment includes a typescript definition file. So if you are using this version you can do following: import * as moment from 'moment'; let now = moment().format('LLLL'); Note: If you have trouble importing moment, try add "allowSyntheticDefaultImports": true in compilerOptions in your tsconfig.json file.

angular2-moment, npm install --save angular2-moment. If you use typescript 1.8, and typings, you may also need to install typings for moment.js: typings install  Moment typescript library uses `void` type as parameter input Breaking change Discussion TypeScript #4073 opened Jul 18, 2017 by chrisleck 8

Microsoft/TypeScript, hmm nothing change error TS2304: Cannot find name 'moment'. I am needing typescript bindings for browsers like in lib.d.ts and related  typescript: 2.1.4 moment: 2.17.1. Notes: Declaration file from the typings works well, and moment it's the only package why I'm still using typings in my project. I checked what the difference is and difference is how they export moment. Instead of export moment they use declare module "moment" { export moment; } 👍

Cannot find name 'Moment', To unsubscribe from this group and stop receiving emails from it, send an email to To post to this group, send  TypeScript supported modules from 1.5+ (besides is anyone is even still using older versions?). For those working on older projects that cannot target ES6 or use module loaders this would be most useful.