I want to use a library ip-address with SystemJS (note, this question may look similar but it is a different problem I ran into trying while trying to accomplish this task).
The library ip-address depends on util-deprecate. It imports it as follows:
var util = require('util');
And then uses it as follows:
Address4.prototype.toV6Group =
util.deprecate(Address4.prototype.toGroup6,
'deprecated: `toV6Group` has been renamed to `toGroup6`');
When I import ip-address in a node project as...
var ipAddress = require('ip-address');
...then I don't get any problems.
When I import ip-address in a SystemJS project...
System.import('ip-address');
...then I get an error:
util.deprecate is not a function
How can I configure SystemJS to perform this import? Currently I am configuring it as so...
const map: any = {
'ip-address':'vendor/ip-address',
'util':'vendor/util-deprecate'
}
const packages: any = {
'ip-address': {main:'ip-address.js'},
'util': {main: 'browser'}
};
Just to save a lookup, the util-deprecate's browser.js file is here, it is exporting the deprecate function directly.
Note, I can get this to work if I modify the ip-address module so that all calls are of the form:
Address4.prototype.toV6Group =
util(Address4.prototype.toGroup6,
'deprecated: `toV6Group` has been renamed to `toGroup6`');
I'd rather not modify a 3rd-party library if I can avoid it however.
Ok, it turns out the issue was that I thought the ip-address
module was using util-deprecate
. It turns out that the way the ip-address
module was importing util...
var util = require('util');
It was not importing util-deprecate
but importing Node's built in package util
. So, in order for ip-address
to truly use util-deprecate
a change will have to be made to the ip-address
module.
Since you tagged with jspm there's a pretty simple solution.
Using jspm
you can simply install ip-address right from npm
using:
jspm install npm:ip-address
which will do all the dependency management for you.
I've tested this in the browser and node.js using the example code ip-address
provides:
import {Address6} from 'ip-address'
const address = new Address6('2001:0:ce49:7601:e866:efff:62c3:fffe');
console.log(address.isValid()); // true
const teredo = address.inspectTeredo();
console.log(teredo.client4); // '157.60.0.1'
and it works totally fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With