"Import Names" import into systemJS

I want to use the ip-address library with SystemJS (note, this question may look similar, but this is another problem that I encountered when trying to complete this task).

The library IP address is dependent on util-deprecate. He 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 the ip address into the node project as ...

 var ipAddress = require('ip-address'); 

... then I have no problem.

When I import an ip address into a SystemJS project ...

 System.import('ip-address'); 

... then I get the error message:

 util.deprecate is not a function 

How to configure SystemJS to perform this import? I am currently setting it up 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'} }; 

To save the search, util.des util-deprecate file here , it exports the deprecate function directly.

Note. I can make this work if I change the ip-address module so that all calls have the form:

 Address4.prototype.toV6Group = util(Address4.prototype.toGroup6, 'deprecated: `toV6Group` has been renamed to `toGroup6`'); 

I would prefer not to modify a third-party library if I can avoid it.

+8
javascript jspm systemjs
source share
2 answers

Well, it turned out that the problem was that I thought the ip-address module was using util-deprecate . It turns out that the ip-address module imported the utility ...

 var util = require('util'); 

He did not import util-deprecate , but import Node's built-in util package. So, in order for ip-address really use util-deprecate , you need to make changes to the ip-address module.

+5
source share

Since you noted jspm there is a pretty simple solution.

Using jspm , you can simply set ip-address directly from npm using:

 jspm install npm:ip-address 

which will do all the dependency management for you.

I tested this in a browser, and node.js, using the ip-address example code, 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 great.

+3
source share

All Articles