Unable to use jsonpath with browserify
> gulp build
[15:44:28] Using gulpfile ~/Desktop/Projects/__workspace__/test/gulpfile.js
[15:44:28] Starting 'build'...
[15:44:28] 'build' errored after 201 ms
[15:44:28] Error: Cannot find module './dict' from '~/Desktop/Projects/__workspace__/test/node_modules/jsonpath'
at ~/Desktop/Projects/__workspace__/test/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
at load (~/Desktop/Projects/__workspace__/test/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
at onex (~/Desktop/Projects/__workspace__/test/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
at ~/Desktop/Projects/__workspace__/test/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:152:21)
sometimes Error: Cannot find module './aesprim' or Error: Cannot find module './slice'
gulpfile:
var gulp = require('gulp');
var browserify = require('browserify');
gulp.task('build', function () {
return browserify('./app.js', {standalone: 'test'})
.bundle()
.pipe(gulp.dest('.'));
});
app.js:
const jp = require('jsonpath')
const data = {
store: {
book: [
{
category: 'reference',
author: 'Nigel Rees',
title: 'Sayings of the Century',
price: 8.95
},
{
category: 'fiction',
author: 'Evelyn Waugh',
title: 'Sword of Honour',
price: 12.99
},
{
category: 'fiction',
author: 'Herman Melville',
title: 'Moby Dick',
isbn: '0-553-21311-3',
price: 8.99
},
{
category: 'fiction',
author: 'J. R. R. Tolkien',
title: 'The Lord of the Rings',
isbn: '0-395-19395-8',
price: 22.99
}
],
bicycle: {
color: 'red',
price: 19.95
}
}
};
const authors = jp.query(data, '$..author');
console.log(authors);
we got similar issue - Error: Cannot find module './dict' from '/Users/smartmouse/node_moudles/jsonpath' Error: Cannot find module './aesprim' from '/Users/smartmouse/node_modules/jsonpath' events.js:183 Is there a workaround?
@smartmouse As a workaround, I used webpack for modules using jsonpath as dep and it worked fine
Also affected by this in loadimpact/jmeter-to-k6#16. I'm sticking to v1.0.1 for now.
@imanjra How are you getting webpack to work? I have a showstopping issue at the moment where webpack fouls up the require.resolve calls to esprima and ../include/(module|action).js and this causes my Node app to fall over on the subsequent fs,readFileSync calls. (I was going to open a new issue for this, but if it's working for you then maybe I don't need to!)
@itowlson
I think you will need option below in webpack options
node: {
fs: 'empty'
}
Our Example
From:
gulp.task('browserify:test', function () {
return browserify('./app.js', {standalone: 'test'})
.bundle()
.pipe(gulp.dest('.'));
});
We changed build task to:
wpOpt = {
entry: './app.js',
output: {
filename: './app.bundle.js,
path: path.resolve(__dirname, './'),
library: 'test', // equivalent of {standalone: 'test'}
libraryTarget: 'umd', // Attaches test to window object
globalObject: 'this' // needed for above line above
},
node: {
fs: 'empty'
},
context: path.resolve(__dirname, '..'),
optimization: {
minimize: false
}
};
}
gulp.task('webpack:test', done => {
webpack(wpOpt,(err, stats) => {
done();
});
});
More on fs issue - https://github.com/webpack-contrib/css-loader/issues/447
Thanks @imanjra. We are in Node so I’m not sure we can get away with the fs trick but I’ll give it a go, and thanks for taking the time to write it up.
@imanjra How are you getting webpack to work? I have a showstopping issue at the moment where webpack fouls up the
require.resolvecalls toesprimaand../include/(module|action).jsand this causes my Node app to fall over on the subsequentfs,readFileSynccalls. (I was going to open a new issue for this, but if it's working for you then maybe I don't need to!)
Did you find a solution for this? I'm experiencing the same issue
@ChillkroeteTTS In my case, I was lucky that the library that was bringing in jsonpath had a newer version which instead brought in jsonpath-plus. The latter doesn't seem to have this problem. This may not be an option for you though of course...
Had the same issue when bundling jsonpath with webpack & nextjs in serverless target mode.
Replacing by jsonpath-plus seems to solve it 👍
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module '..' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module './dict' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module './aesprim' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module './slice' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module './handlers' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module './grammar' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:51] Browserify error: Can't walk dependency graph: Cannot find module './parser' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
[13:59:52] Browserify error: Can't walk dependency graph: Cannot find module './support/isBuffer' from '.../node_modules/jsonpath'
required by .../node_modules/jsonpath/jsonpath.js
I ran in to an issue with browserify and jsonpath as well. However, the issue seems to be that the paths to modules in the require statments in the jsonpath.js file (https://github.com/dchester/jsonpath/blob/master/jsonpath.js#L5117) seem to be incorrect.