Issue
Using mgechev's angular2-seed, I'm trying to get to grips with Angular2 and Typescript for a new project, but have run into this problem.
I want to use Numeral in a component, so I:
- Installed Numeral using
npm install numeral
- Installed the typing for Numeral using
typings install dt~numeraljs --global --save
- In my component added
import { numeral } from '/typings/globals/numeraljs';
- Added the line of code:
let num:Number = new Number(numeral().unformat(text));
So far, so good. Everything seems to transpile ok. Until I get to the browser, where I get in the console:
Error: XHR error (404 Not Found) loading http://localhost:5555/typings/globals/numeraljs.js(…)
What am I doing wrong here? Have I missed a step out to tell Typescript where the actual code is?
Solution
Typically what you want to do is, if the package is not a native Typescript module:
import * as numeral from 'numeral';
The typings folder is just for telling Typescript what the type definitions are, so it will use it for code highlighting and linting. The actual module you want to import sits in the node_modules
folder and can be imported with its name.
If it's still complaining about not finding the numeral
module you could add
/// <reference path="typings/globals/numeraljs/numeraljs.d.ts"/>
or wherever the Typescript definition file is stored.
Answered By - Maximilian Riegler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.