1

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?

3
  • did you do npm install ? Commented May 4, 2016 at 20:48
  • typings is for definition files. Did you try installing it using npm install request? Commented May 4, 2016 at 20:48
  • yes I did npm install. I didn't mention that because I thought it was obvious Commented May 4, 2016 at 20:53

1 Answer 1

2

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';
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.