jsonpath
jsonpath copied to clipboard
pre-bundled jsonpath.js crashes on $[a,b] selector: does not include _uniq from underscore
The pre-bundled jsonpath.js file included in the node package will crash when attempting to use an array selector operation due to missing underscore functions.
Webpack has given "underscore" module index 9, which in the bundle is:
9:[function(require,module,exports){
},{}]
As this exports no content, the line
var _uniq = require('underscore').uniq;
sets _uniq to undefined, causing the crash when unique() is called on line 4855.
Of interest; a quick and probably non-comprehensive search only turned up _uniq as the only part of underscore being used. The bundle size could be kept to a minimum by simply bundling the lodash single-module equivalent lodash.uniqby.
(not to be confused with lodash.uniq, which does not accept the iterator function as the second argument)
Ooh, didn't see this... should have looked harder -.-. Surprised this import issue didn't get fixed for the last release... A bit more info on a reproducable use case in this issue that i just closed: https://github.com/dchester/jsonpath/issues/88
The unit tests could do with being run on these bundled files.
Looks like the issue here: https://github.com/dchester/jsonpath/blob/master/Gruntfile.js#L33 Browserify is ignoring all these dependencies but the source always assumes that they exist.
Another one (seperate issue though) is "fs" which has a check for "readFileSync" https://github.com/dchester/jsonpath/blob/master/lib/grammar.js#L101 But the actual require itself fails in the browser. https://github.com/dchester/jsonpath/blob/master/lib/grammar.js#L2
@dchester
Hi,
Same issue
Log: (import in l. 4606 - var _uniq = require('underscore').uniq; )
vue.runtime.esm.js?2b0e:1888 TypeError: _uniq is not a function
at unique (jsonpath.js?52cd:4851)
at Handlers.subscript-child-union (jsonpath.js?52cd:4690)
at eval (jsonpath.js?52cd:5001)
at Array.forEach (<anonymous>)
at eval (jsonpath.js?52cd:4998)
at Array.forEach (<anonymous>)
at JSONPath.nodes (jsonpath.js?52cd:4992)
at JSONPath.query (jsonpath.js?52cd:4958)
at fetchJsonPathData (proccess.js?25a6:41)
at fetchData (proccess.js?25a6:24)
Can this issue been fixed ?
Regars
I am having this issue as well, any ideas on how to solve it
Please fix this issue. It would be better to remove underscore library dependency and write a function in it's place.