Can i use npm packages directly inside angular 2?

I am trying to use npm package ‘js-md5’ in my angular 2 app.

I tried directly importing it from its node_module folder but it doesn’t work. So, is there any solution for this?

can u share the folder directory ? and how you try to connected it?

I tried using all of these
> import ‘js-md5’;
> import ‘js-md5/src/md5’;
> var md5 = require(‘js-md5’);

did you run npm install for that package? What error does it throw when you require the package?

In case of require it says “Cannot find name ‘require’” maybe because its type script.

And when doing import statement it doesn’t find the function name.

It seems to me that typescript cannot find the declaration files for node. There could be something wrong with the way the project is configured, but its impossible to tell without looking at it in more detail.

Just tested it:

Run: npm i js-md5
And this is the code in a component:

import * as md5 from 'js-md5'
1 Like

@BenGitter Works like magic.

Thanks alot:grin:

LifeSaver !!! this is