hassansin / parse-address

US Street Address Parser
http://hassansin.github.io/parse-address/
Other
157 stars 81 forks source link

Undefined is not a function. #21

Open cezarcarvalhaes opened 5 years ago

cezarcarvalhaes commented 5 years ago

Running parseLocation inside a React app that a submodule inside a larger Gatsby project.

Getting a strange error when using parser.parseLocation(value). Browser is returning 'undefined is not a function.' Line 521 of parseaddress/address.js. Here's the full block:

    Addr_Match = {
      type    : flatten(Street_Type).sort().filter(function(v,i,arr){return arr.indexOf(v)===i }).join('|'),
      fraction : '\\d+\\/\\d+',
      state   : '\\b(?:' + keys(State_Code).concat(values(State_Code)).map(XRegExp.escape).join('|') + ')\\b',
      direct  : values(Directional).sort(function(a,b){return a.length < b.length}).reduce(function(prev,curr){return prev.concat([XRegExp.escape(curr.replace(/\w/g,'$&.')),curr])},keys(Directional)).join('|'),
      dircode : keys(Direction_Code).join("|"),
      zip     : '(?<zip>\\d{5})[- ]?(?<plus4>\\d{4})?',
      corner  : '(?:\\band\\b|\\bat\\b|&|\\@)',
    };

I suspect it's related to how XRegExp is being required at the top of the same file:

   XRegExp = __webpack_require__(/*! xregexp/src/xregexp.js */ "./node_modules/xregexp/src/xregexp.js");

Encounter a similar issue when running parser.parseAddress(value). Browser returns error: 'XRegExp.exec is not a function'. Line 682 of parseaddress/address.js:

  parser.parseAddress = function(address){
    lazyInit();
    var parts = XRegExp.exec(address,Addr_Match.address);
    return parser.normalize_address(parts);
  };

I've confirmed that xregexp is also an installed dependency.

Please advice when you get a chance, thanks!