Reputation: 1911
I'm trying to install a module named "request" https://github.com/request/request
in my angular 2 typescript project but I can't get it imported for some reason.
I tried installing the normal way with npm install --save request and I tried typings install request --ambient --save aswell although I don't know what exactly that does anyway.
I'm working off of this boilerplate https://github.com/mgechev/angular2-seed which in the wiki suggests that install modules is as easy as using npm install and then
import * as jwt from 'angular2-jwt/angular2-jwt';
But I can't import my request module for some Reason.
This is my import line
import * as request from 'request';
Do I need to reference the module elsewhere somehow?
Upvotes: 1
Views: 668
Reputation: 202316
The request
module isn't designed for browsers only for Node applications. You should use the browser-request
instead.
That being said, installing the module with NPM isn't directly usable into your application:
For compilation you need to install a typing for compilation. A kind of contract of the API of your library. This way the TypeScript compilation will know which classes, methods and properties are present in the module.
For execution you need to reference your module when loading your application. For example with SystemJS you need something like that:
System.config({
map: {
request: 'node_modules/browser-request/index.js'
}
});
This way you will be able to import the library this way:
import * as request from 'request';
Upvotes: 2