jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

this.nodes is not a function

Open pankajashankar opened this issue 6 years ago • 5 comments
trafficstars

Hi, Premise:

  1. I have a angular 7 custom component library xyz-component. Within the library in one of the child component I use jsonpath which I installed with npm install jsonpath and the version of 1.0.1 got installed which I verified in the package.json.
  2. I built the xyz-component library with npm_pack and a xyz-component.0.0.1.tgz is created.
  3. I deploy the tgz file with npm install in my consuming project for e.g. consumingmain-portal everything goes fine.
  4. Did a npm install of jsonpath in the consuming project as well
  5. When I try to run the consuming application - with ng serve I get the error node_modules\jsonpath\lib\index.js change all references to'this' to JSONPath.prototype - resolve ‘ this.nodes is not a function’ issue. Note: change is in node_modules of consuming project_

Not sure why it gives that error but when I modify the index.js under node_modules\jsonpath to change this to JSONPath.prototype_, and re-run I do not get the error.

Please let me know what is the issue here. Also mainly what is the solution.

--Thanks

pankajashankar avatar Apr 22 '19 17:04 pankajashankar

think the answer to this is to follow the docs exactly:

// https://github.com/dchester/jsonpath#jpqueryobj-pathexpression-count

import jp from 'jsonpath'
jp.query(BLAH)

If you destructure the import (as i was):

import {query} from 'jsonpath'
query(BLAH)

It gives the error you describe. I'd say it was down to webpack treeshaking or something but declaring as an external didn't help either..

elmpp avatar Aug 21 '19 06:08 elmpp

in my case I have to import jsonpath in the following way

const jsonpath = require("jsonpath")

guoliang avatar Mar 11 '21 14:03 guoliang

I had the same issue because I was calling : jp.query.call(null, data, path) When I changed this parameter from null to jp it solved the problem. jp.query.call(jp, data, path)

btw, my import is import jp from 'jsonpath'

danbars avatar Aug 23 '21 19:08 danbars

I had the same issue because I was calling : jp.query.call(null, data, path) When I changed this parameter from null to jp it solved the problem. jp.query.call(jp, data, path)

btw, my import is import jp from 'jsonpath'

belated update from my initial post. I did that change recently also and got it to work. so in conclusion it seems like importing individual function does not work, instead you have to import the entire content.

guoliang avatar Aug 23 '21 19:08 guoliang

I think this needs to be fixed so that tree shaking can be done to only use functions that are required..

LRagji avatar Jan 27 '23 07:01 LRagji