jz87
jz87

Reputation: 9627

How do I import modules in Angular2?

I keep getting module not found errors whenever I try to import modules. For some reason import {} from 'angular2/core' works fine but importing any other module doesn't work.

I'm trying to import * as Crypto from 'crypto-browserify' which is located in node_modules. I tried setting up the path in System.Config to point the path to the correct directory, but then all the modules that crypto-browserify references can't be found unless I manually include them in the path also. How do I set it up so it looks for the module A in /node_modules/A?

Upvotes: 1

Views: 1772

Answers (1)

inoabrian
inoabrian

Reputation: 3800

So I got it working on my end. You have to include it in your HTML

<script src="wwwroot/lib/crypto-js/crypto-js.js"></script>

Then you have to add the reference to the TSD in your TS file

/// <reference path="../tsd/crypto-js/cryptojs.d.ts" />
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/crypto-js/crypto-js.d.ts

and in your code you can refernce it through the global variable it exports.

CryptoJS.

Upvotes: 2

Related Questions