6

We use a webpack to bundle our lambdas before we deploy them. Ever since we added code that has a dependency on "jsonpath," the code fails immediately with the following.

TypeError: Cannot read property '1' of undefined at isFileType (fs.js:163:16) at Object.readFileSync (fs.js:346:16) at Object.28729 (/.../bundle.js:2:4710658)

I am pretty new to Webpack, so I am unsure where to go with this. Code works fine, but it's not bundled. Also, I have tried different versions of Webpack. Can someone suggest how to troubleshoot this?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
KickinMhl
  • 1,218
  • 3
  • 14
  • 32

1 Answers1

0

I got a similar error within Azure Functions, which is an alternative to AWS Lambdas.

Error: ENOENT: no such file or directory, open './node_modules/jsonpath/include/module.js'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)

Since the error message was more expressive, it turned out, that the jsonpath package expects several files next to its location, since it uses require.resolve.

You can fix the issue by copying the required files next to your function, e.g. using copy-webpack-plugin in your webpack.config.js.

plugins: [
    new CopyWebpackPlugin({
        patterns: [
            // required node_modules for jsonpath (see https://github.com/dchester/jsonpath/search?q=require.resolve)
            {from: 'node_modules/jsonpath/include', to: 'node_modules/jsonpath/include'},
            {from: 'node_modules/esprima', to: 'node_modules/esprima'},
        ]
    })
],
sschmeck
  • 7,233
  • 4
  • 40
  • 67