JSONPath-Plus / JSONPath

A fork of JSONPath from http://goessner.net/articles/JsonPath/
Other
963 stars 169 forks source link

Error in angular prod build #129

Closed frothenberger closed 3 years ago

frothenberger commented 4 years ago

I tried using this library with angular 9.1.11. The serve:dev works fine, but the prod build fails because the module 'vm' is not present.

ERROR in ./node_modules/jsonpath-plus/dist/index-es.js Module not found: Error: Can't resolve 'vm' in '/Users/froth/Documents/Repositories/medusa/login-ui/node_modules/jsonpath-plus/dist' resolve 'vm' in '/Users/froth/Documents/Repositories/medusa/login-ui/node_modules/jsonpath-plus/dist' Parsed request is a module using description file: /Users/froth/Documents/Repositories/medusa/login-ui/node_modules/jsonpath-plus/package.json (relative path: ./dist) Field 'browser' doesn't contain a valid alias configuration

Is there a way to fix this (e.g. suppress this dependency)?

brettz9 commented 4 years ago

I think we'll need a separate builds, one for Node and one for others, to avoid these kind of static analysis problems--I think React Native may have such an issue as well, IIRC.

brettz9 commented 4 years ago

I have made a new build of JSONPath which I hope may fix this issue.

Could you see if it works in temporarily setting this in your package.json deps:

"jsonpath-plus": "https://github.com/JSONPath-Plus/JSONPath#builds-node-browser"

...and then running again a local npm install.

If you can test this, I can see about pushing it as a new release.

If that doesn't work (or if you set aliasFields but without browser as below), you may need to set this in your Webpack config: https://webpack.js.org/configuration/resolve/#resolvealiasfields

module.exports = {
  //...
  resolve: {
    aliasFields: ['browser']
  }
};

If that doesn't work, or if you are using mainFields already, you may need to set per https://webpack.js.org/configuration/resolve/#resolvemainfields , ensuring that browser is before any of the other items (or otherwise, the Node build with vm might get preferred, causing your errors):

module.exports = {
  //...
  resolve: {
    mainFields: ['browser', 'module', 'main']
  }
};

If it still doesn't work, I'd probably need to have a minimal reproduction repo prepared with a simple Webpack config that reproduces the problem (I'm not deeply familiar with Webpack, but having a minimal test repo should help).

If it works, please also let us know what, if any, changes you had to make.

Thanks!

frothenberger commented 4 years ago

Hi, thanks a lot for this update!

I'm currently on vacation. But I'm happy to test this out, once I'm back.

abhishekarun commented 4 years ago

When is this getting fixed? Do we have a date?

brettz9 commented 4 years ago

@frothenberger : Are you going to take a look?

@abhishekarun : if you can confirm the PR (#130) is working on Angular, I'm happy to merge.

jainanuj0812 commented 4 years ago

@brettz9 I have tested angular app with your changes and still facing the issue.

brettz9 commented 4 years ago

@jainanuj0812 : Thank you... Could you give the exact error message (you can leave out the first part of your own paths, but keep the node_modules path)?

varubi commented 4 years ago

I was able to build by adding the following to my angular project's package.json

  "browser": {
    "vm": false
  }
brettz9 commented 3 years ago

@varubi : If you are speaking about adding that directive against PR #130 (or if you can test your code against that PR), it should really help us going into the future if you might be able to indicate the exact error message you get (including listing the path into node_modules) when you don't include that directive. The PR shouldn't need that directive because the browser build points to a file without trying to load a native vm.

bgBond commented 3 years ago

Any update? I am getting this error also in dev mode (Angular 10)-

[ERROR] ERROR in ./node_modules/jsonpath-plus/dist/index-es.js [ERROR] Module not found: Error: Can't resolve 'vm' in '..\node_modules\jsonpath-plus\dist'

toamitc commented 3 years ago

Same error in Angular 10 for me as well, any solution for this? ERROR in ./node_modules/jsonpath-plus/dist/index-es.js Module not found: Error: Can't resolve 'vm' in '/node_modules/jsonpath-plus/dist'

brettz9 commented 3 years ago

@bgBond and @toamitc : Please read the comments above starting at https://github.com/JSONPath-Plus/JSONPath/issues/129#issuecomment-656984652 and continuing on to the end.

papadi commented 3 years ago

To reproduce the problem please follow these steps:

npm install -g @angular/cli ng new angular-tour-of-heroes cd .\angular-tour-of-heroes npm install JSONPath --save-dev`

Then add the following two lines at the top of app.component.ts import jp from 'JSONPath'; jp.query({}, '');

And then run... npm start

I hope this helps.

brettz9 commented 3 years ago

@papadi please note that our package is jsonpath-plus, not JSONPath! Also, the API is different (see our README). :-)

However, your instructions on how to quickly set up an angular app and reproduce kindly helped me confirm my latest fixes just now are working. Released as v5.0.0. Thanks very much!