I would like to use an available npm package in my Angular 4 component but am struggling to make it work. The package is called 'ip' available from https://www.npmjs.com/package/ip
I have added the package as follows:
npm install ip --save
npm install --save @types/ip
and in my app.module.ts I have:
import { isV4Format } from 'ip';
and I add isV4Format to the imports list in app.module.ts
I then try to use the ip package it in my class as follows:
import { isV4Format } from 'ip';
export class TabValidator {
private static _check(address: string): any {
const ip = require('ip');
if (!myip.isV4Format(address)) { return { 'wrongFormat': true }; }
return null;
}
}
The compiler complains about the component:
Cannot find name 'require'
and about app.module.ts:
Argument of type '{ declarations: (typeof InterfacesComponent | typeof EditnicComponent | typeof AppComponent)[]; i...' is not assignable to parameter of type 'NgModule'.
Can someone tell me what's wrong with the above? I suspect there are a few things wrong. I found 2 similar question on SO but they appear to be for different angular versions.