Giter Club home page Giter Club logo

Comments (4)

itaysabato avatar itaysabato commented on September 27, 2024 3

This works but makes Webpack issue a warning:

WARNING in ./~/jsonpath/jsonpath.js
Critical dependencies:
3:481-488 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/jsonpath/jsonpath.js 3:481-488

Additionally, it does not play nice with typescript imports and DefinitelyTyped.

It would make for a much smoother experience if require('jsonpath') simply worked with Webpack.

Thanks!

UPDATE

There is a better workaround that lets you use require('jsonpath') or import * as jsonpath from 'jsonpath' if you use typescript. It requires two changes to webpack.config.js:

First you need to add the following.

node: {
    fs: "empty"
}

See https://webpack.github.io/docs/configuration.html#node for more information.

Then simply add a json-loader:

loaders: [
    ...
    {
        test: /\.json$/,
        loader: "json-loader"
    },
    ...
]

This configuration may be trivial for some people but it took me a while to figure out. Now I get a different, less disturbing, warning (the same warning as in the first comment by @Murriouz) but it works fine in the browser:

WARNING in ./~/jsonpath/lib/grammar.js
Critical dependencies:
4:0-7 require function is used in a way in which dependencies cannot be statically extracted
4:18-25 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/jsonpath/lib/grammar.js 4:0-7 4:18-25

from jsonpath.

dchester avatar dchester commented on September 27, 2024

I would suggest using the pre-built jsonpath.js library at the root of the repo, instead of asking webpack to build the whole thing from scratch. Does that work for you?

That lib/grammar.js file is really only useful for generating the static jsonpath parser itself, not something you probably want at run-time.

from jsonpath.

thethreeonee avatar thethreeonee commented on September 27, 2024

That works for me. Thanks.

from jsonpath.

janjachacz avatar janjachacz commented on September 27, 2024

I'm using the pre-built jsonpath.js file but there are some issues..

  • When using $..book[0,1], I receive an error TypeError: _uniq is not a function.
  • When using $..book[-1:], I receive all 5 books instead of the last. Note that $..book[(@.length-1)] works as expected.

from jsonpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.