-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when jsonpath is loaded by webpack #50
Comments
I believe replacing the fs.readFileSync and require.resolve stubs by adding this code right before the export should fix the issue: if (fs.readFileSync) {
grammar.moduleInclude = fs.readFileSync(require.resolve("../include/module.js"));
grammar.actionInclude = fs.readFileSync(require.resolve("../include/action.js"));
} I cloned the repo and tested this and it works for me. |
I am transpiling using webpack, but targeting for node (not browser). I'm getting the following error:
I think, the check for if (fs.readFileSync && typeof __webpack_require__ !== 'function') {
grammar.moduleInclude = fs.readFileSync(require.resolve("../include/module.js"));
grammar.actionInclude = fs.readFileSync(require.resolve("../include/action.js"));
} But, I'm not sure whether it's good idea to do that. |
My workaround for this is to treat jsonpath as an external, thus it will be loaded from My webpack config as an example for the workaround: const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: {
handler: './handler.js'
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
target: 'node',
externals: [nodeExternals({
whitelist: [/^(?:(?!jsonpath|aws-sdk).)*$/]
})],
module: {
loaders: [{
test: /(\.json)|(package\.json)$/,
loader: 'json-loader'
}, {
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
babelrc: true
}
}]
},
resolve: {
root: [
path.resolve(__dirname, 'node_modules')
],
extensions: ['', '.js', '.json']
}
}; |
Why is |
By removing `grammar.moduleInclude` as well as `grammar.actionInclude` (both not used inside jsonpath), the library can be used with webpack when targeting node.
Is there any solution or workaround for this issue? |
any updates? |
@jefftham @faizhasim @blobcat I find another library: |
The dynamic import that was merged near the beginning of this thread breaks vite/sveltekit pretty bad and I can't seem to figure out a workaround. Any ideas? |
@brianorwhatever I migrated to this fork: https://github.com/astronautlabs/jsonpath. Works with esm, has ts definitions, same API. |
I have been trying to integrate jsonpath into my webpack project, but I'm getting blocked the following error:
It appears the error is coming from the following line in grammar.js when it tries to stub out require.resolve:
The above line of code is rewritten by webpack into this, which is invalid:
For reference, I am using webpack v2.2.0-rc.3
The text was updated successfully, but these errors were encountered: