3
votes

I am trying to figure out how to use various 3rd party libraries within Angular CLI environment. The official wiki page was very useful to get going with moment.js lib. However, I ran into trouble when trying to install typings for the library (step 1a in the tutorial):

typings install moment --save

typings WARN hastypings Typings for "moment" already exist in 
"node_modules/moment/moment.d.ts". You should let TypeScript resolve
the packaged typings and uninstall the copy installed by Typings

typings ERR! message Unable to find "moment" ("npm") in the registry.
Did you want to try searching another source? Also, if you want contribute
these typings, please help us: https://github.com/typings/registry

My setup for reference:

angular-cli: 1.0.0-beta.5
node: 4.4.4
os: darwin x64
typings: 1.0.5

Although the error message suggests to "uninstall the copy installed by Typings" it seems that there is no new .d.ts files added to the project folder. What would be the best way to include 3rd party typings in this case?

1
Have you solved your problem ? which version of angular2 you are using ?pd farhad

1 Answers

0
votes

Short answer: Run npm install @types/moment.

Explanation:

You've got at least a couple problems here.

(1) As the TypeScript team announced, "getting type declarations in TypeScript 2.0 will require no tools apart from npm" (emphasis theirs). This means that typings has been deprecated, and npm alone is needed to install typing files. A simple example would be npm install --save @types/lodash. Take note of @types. All typings now go in node_modules/@types. With this in mind, we can look at your second problem.

(2) You're using typings, a TypeScript 1 tool, with angular-cli, which uses TypeScript 2. They aren't compatible. Instead, you can install momentjs's typings with npm install @types/moment.

Finally--and not directly related to your question--you may be interested in angular2-moment, an open source library that ports momentjs to Angular 2.