Skip to content

cannot bundle with CDK/esbuild and use in AWS Lambda #168

Open

Description

@pveller

Hey guys,

awesome library. Love it! But I can't use it in lambda packaged with esbuild without some hacking because of this:

https://github.com/dchester/jsonpath/blob/master/lib/grammar.js#L102

It comes down to this in runtime:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '../include/module.js'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module '../include/module.js'",
        "Require stack:",
        "- /var/task/index.js",
        "- /var/runtime/UserFunction.js",
        "- /var/runtime/index.js",
        "    at _loadUserApp (/var/runtime/UserFunction.js:202:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:242:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

There are no files other than nicely bundled index.js after esbuild

Thanks!

Activity

  1. askluke commented on Apr 12, 2022

    @askluke

    Same problem here. Any quick fixes for this?

  2. EarthyOrange commented on Sep 23, 2022

    @EarthyOrange

    Was a fix for this issue found?

    It seems like esbuild is shaking off the include folder. That being said, can you guys create a repro project with esbuild and the input that is creating this problem? I can look in to it and attempt a fix.

  3. pveller commented on Sep 30, 2022

    @pveller
    Author
  4. xgpayfit commented on Jan 16, 2023

    @xgpayfit

    Hi ! It's shaked off because both files in the missing "include" folder are required dynamically (no static require / import from) :
    https://github.com/dchester/jsonpath/blob/master/lib/grammar.js#L102

    if (fs.readFileSync) {
      grammar.moduleInclude = fs.readFileSync(require.resolve("../include/module.js"));
      grammar.actionInclude = fs.readFileSync(require.resolve("../include/action.js"));
    }
    

    This syntax forbids all usage of this library with a bundler (esbuild, webpack, nx, ...) that uses tree shaking...

  5. brianorwhatever commented on Jun 14, 2023

    @brianorwhatever

    this dynamic import needs to be fixed it breaks a lot of things

  6. j-flat commented on Jun 28, 2024

    @j-flat

    Would you mind to take a look on this issue and the proposed fix #172 @dchester?

    There are large players using your library as their dependency, I'm currently getting issues through contentful-export being dependent on this library.

    Maintaining open-source library aside from your daily job is probably huge hassle, maybe it would be worth to consider picking some of the helpful fellows from active PR openers as contributors with a merge rights?

  7. mgoulet101 commented on Oct 16, 2024

    @mgoulet101

    I just ran into this issue, and converted to jsonpath-plus. For my application, it was a drop-in replacement that does not suffer from this behavior. A coworker indicated that the esbuild "dynamic modules" plugin is now deprecated and presumably intrinsically supports dynamically loaded modules in newer versions (24.x as of now). So this may be fixed and therefore jsonpath might work, though did not investigate that approach.

    One thing to consider, jsonpath-plus is no longer actively maintained. That could present issues in the future.

    BTW, I am specifically using a JSON path to navigate to a child-object based on a root object from which the JSON path is derived. For me the issue was an AWS CDK deployment that uses esbuild under the hood. I received warnings during deployment about those dynamic loaded modules in jsonpath, then module-not-found errors once running in the Lambda in the cloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions