aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

aws-lambda-nodejs: package.json type field is not preserved with external node_modules

Open ben-eb opened this issue 1 year ago • 9 comments

Describe the bug

Hello 👋

I am using https://knexjs.org/ to apply database migrations via Lambda. This requires some modules to be loaded externally due to dynamic import which is working well with CommonJS.

However when porting the code to ES Modules (and using OutputFormat.ESM) I am seeing some module loading issues due to the type key not being set in the generated package.json file. I traced this back to this line:

https://github.com/aws/aws-cdk/blob/ac3ffa5cf8d9a1b664ccd5fcbe889e437be3ca5d/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts#L288

This is surprising as it implicitly changes the output format of the bundle back to CommonJS.

Regression Issue

  • [ ] Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The type property should be added to the package.json file that is generated when using the nodeModules option, but only when in the source package.json file.

Current Behavior

No type property is added to the generated package.json.

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import { type Construct } from 'constructs';
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
import * as Lambda from 'aws-cdk-lib/aws-lambda';

export class InfrastructureStack extends cdk.Stack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        const banner =
            "const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);";
        
        new NodejsFunction(this, 'lambda', {
            functionName: 'test-knex-esm',
            entry: 'index.ts',
            runtime: Lambda.Runtime.NODEJS_20_X,
            bundling: {
                banner,
                format: OutputFormat.ESM,
                mainFields: ['module', 'main'],
                nodeModules: ['knex'],
            }
        })
    }
}

index.ts can have any contents to replicate this issue.

Possible Solution

The type property is also added to the generated package.json when using the nodeModules option and only if it is present in the source package.json. However it may be worth considering to be explicit here as per the Node.js recommendation (and setting the type based on the value of OutputType):

Writing ES module syntax in "ambiguous" files incurs a performance cost, and therefore it is encouraged that authors be explicit wherever possible. In particular, package authors should always include the "type" field in their package.json files, even in packages where all sources are CommonJS. Being explicit about the type of the package will future-proof the package in case the default type of Node.js ever changes, and it will also make things easier for build tools and loaders to determine how the files in the package should be interpreted.

https://nodejs.org/api/packages.html#determining-module-system

Additional Information/Context

There is a workaround here which is to write the source code in .mjs or .mts explicitly and not rely on the package.json lookup to determine the default module system that .js uses.

CDK CLI Version

v2.174.0

Framework Version

v2.174.0

Node.js Version

v20.18.0

OS

Mac OS X

Language

TypeScript

Language Version

TypeScript 5.7.2

Other information

No response

ben-eb avatar Jan 07 '25 12:01 ben-eb

@ben-eb Good morning. Thanks for opening the issue. Could you please also share the package.json, preferably self-contained project for analysis? Also elaborate in your use case, where the type field is defined, which is not preserved?

Thanks, Ashish

ashishdhingra avatar Jan 10 '25 19:01 ashishdhingra

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Jan 12 '25 20:01 github-actions[bot]

Also elaborate in your use case, where the type field is defined, which is not preserved?

Top level field of package.json:

{
  "name": "cdk-knex-issue",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "cdk deploy"
  },
  "dependencies": {
    "aws-cdk-lib": "^2.175.1",
    "constructs": "^10.4.2",
    "knex": "^3.1.0"
  },
  "devDependencies": {
    "aws-cdk": "^2.175.1"
  }
}

ben-eb avatar Jan 13 '25 09:01 ben-eb

Also elaborate in your use case, where the type field is defined, which is not preserved?

Top level field of package.json:

{ "name": "cdk-knex-issue", "private": true, "type": "module", "scripts": { "test": "cdk deploy" }, "dependencies": { "aws-cdk-lib": "^2.175.1", "constructs": "^10.4.2", "knex": "^3.1.0" }, "devDependencies": { "aws-cdk": "^2.175.1" } }

@ben-eb Thanks for the input. Could you please also share the package.json, preferably self-contained project for analysis?

ashishdhingra avatar Jan 14 '25 19:01 ashishdhingra

Alright, here is an entire project (typescript removed for brevity):

src/bin.js

#!/usr/bin/env node

import process from 'node:process';
import * as cdk from 'aws-cdk-lib';
import { InfrastructureStack } from './stack.js';

const app = new cdk.App();

new InfrastructureStack(app, 'CdkEsbuildIssue');

src/index.js

export async function handler () {

}

src/stack.js

import * as path from 'node:path';
import url from 'node:url';
import * as cdk from 'aws-cdk-lib';
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
import * as Lambda from 'aws-cdk-lib/aws-lambda';

export class InfrastructureStack extends cdk.Stack {
    constructor(scope, id) {
        super(scope, id);

        const banner =
            "const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);";

        const root = url.fileURLToPath(new URL('.', import.meta.url));

        new NodejsFunction(this, 'lambda', {
            functionName: 'test-knex-esm',
            entry: path.join(root, 'index.js'),
            runtime: Lambda.Runtime.NODEJS_20_X,
            bundling: {
                banner,
                format: OutputFormat.ESM,
                mainFields: ['module', 'main'],
                nodeModules: ['knex'],
            }
        })
    }
}

cdk.json

{
  "app": "node src/bin.js"
}

package.json

{
  "name": "cdk-knex-issue",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "cdk deploy"
  },
  "dependencies": {
    "aws-cdk-lib": "^2.175.1",
    "constructs": "^10.4.2",
    "knex": "^3.1.0"
  },
  "devDependencies": {
    "aws-cdk": "^2.175.1",
    "esbuild": "^0.24.2"
  }
}

package-lock.json

{
  "name": "cdk-knex-issue",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "cdk-knex-issue",
      "dependencies": {
        "aws-cdk-lib": "^2.175.1",
        "constructs": "^10.4.2",
        "knex": "^3.1.0"
      },
      "devDependencies": {
        "aws-cdk": "^2.175.1",
        "esbuild": "^0.24.2"
      }
    },
    "node_modules/@aws-cdk/asset-awscli-v1": {
      "version": "2.2.218",
      "resolved": "https://registry.npmjs.org/@aws-cdk/asset-awscli-v1/-/asset-awscli-v1-2.2.218.tgz",
      "integrity": "sha512-t5M+dk7qNM0N6ZbHVDs/6lO7xPw4ogUUsTbXzAfnqrpZQ/wKpphwgBxTNrHMV+NKOFxyCbF5fWUAD7I36jRqZw==",
      "license": "Apache-2.0"
    },
    "node_modules/@aws-cdk/asset-kubectl-v20": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/@aws-cdk/asset-kubectl-v20/-/asset-kubectl-v20-2.1.3.tgz",
      "integrity": "sha512-cDG1w3ieM6eOT9mTefRuTypk95+oyD7P5X/wRltwmYxU7nZc3+076YEVS6vrjDKr3ADYbfn0lDKpfB1FBtO9CQ==",
      "license": "Apache-2.0"
    },
    "node_modules/@aws-cdk/asset-node-proxy-agent-v6": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/@aws-cdk/asset-node-proxy-agent-v6/-/asset-node-proxy-agent-v6-2.1.0.tgz",
      "integrity": "sha512-7bY3J8GCVxLupn/kNmpPc5VJz8grx+4RKfnnJiO1LG+uxkZfANZG3RMHhE+qQxxwkyQ9/MfPtTpf748UhR425A==",
      "license": "Apache-2.0"
    },
    "node_modules/@aws-cdk/cloud-assembly-schema": {
      "version": "39.1.44",
      "resolved": "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-39.1.44.tgz",
      "integrity": "sha512-iW9qAEsRj22a9/ZRBXBgK5O671Lnecsa1I89I7pswZk8d9+LrOj4rBXl+vjioB8vBjXIyi9Fevvz3lLt3Jiw7w==",
      "bundleDependencies": [
        "jsonschema",
        "semver"
      ],
      "license": "Apache-2.0",
      "dependencies": {
        "jsonschema": "~1.4.1",
        "semver": "^7.6.3"
      }
    },
    "node_modules/@aws-cdk/cloud-assembly-schema/node_modules/jsonschema": {
      "version": "1.4.1",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": "*"
      }
    },
    "node_modules/@aws-cdk/cloud-assembly-schema/node_modules/semver": {
      "version": "7.6.3",
      "inBundle": true,
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/@esbuild/aix-ppc64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz",
      "integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==",
      "cpu": [
        "ppc64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "aix"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/android-arm": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.2.tgz",
      "integrity": "sha512-tmwl4hJkCfNHwFB3nBa8z1Uy3ypZpxqxfTQOcHX+xRByyYgunVbZ9MzUUfb0RxaHIMnbHagwAxuTL+tnNM+1/Q==",
      "cpu": [
        "arm"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "android"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/android-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.2.tgz",
      "integrity": "sha512-cNLgeqCqV8WxfcTIOeL4OAtSmL8JjcN6m09XIgro1Wi7cF4t/THaWEa7eL5CMoMBdjoHOTh/vwTO/o2TRXIyzg==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "android"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/android-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.2.tgz",
      "integrity": "sha512-B6Q0YQDqMx9D7rvIcsXfmJfvUYLoP722bgfBlO5cGvNVb5V/+Y7nhBE3mHV9OpxBf4eAS2S68KZztiPaWq4XYw==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "android"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/darwin-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz",
      "integrity": "sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "darwin"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/darwin-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.2.tgz",
      "integrity": "sha512-WeSrmwwHaPkNR5H3yYfowhZcbriGqooyu3zI/3GGpF8AyUdsrrP0X6KumITGA9WOyiJavnGZUwPGvxvwfWPHIA==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "darwin"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/freebsd-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.2.tgz",
      "integrity": "sha512-UN8HXjtJ0k/Mj6a9+5u6+2eZ2ERD7Edt1Q9IZiB5UZAIdPnVKDoG7mdTVGhHJIeEml60JteamR3qhsr1r8gXvg==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "freebsd"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/freebsd-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.2.tgz",
      "integrity": "sha512-TvW7wE/89PYW+IevEJXZ5sF6gJRDY/14hyIGFXdIucxCsbRmLUcjseQu1SyTko+2idmCw94TgyaEZi9HUSOe3Q==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "freebsd"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-arm": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.2.tgz",
      "integrity": "sha512-n0WRM/gWIdU29J57hJyUdIsk0WarGd6To0s+Y+LwvlC55wt+GT/OgkwoXCXvIue1i1sSNWblHEig00GBWiJgfA==",
      "cpu": [
        "arm"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.2.tgz",
      "integrity": "sha512-7HnAD6074BW43YvvUmE/35Id9/NB7BeX5EoNkK9obndmZBUk8xmJJeU7DwmUeN7tkysslb2eSl6CTrYz6oEMQg==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-ia32": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.2.tgz",
      "integrity": "sha512-sfv0tGPQhcZOgTKO3oBE9xpHuUqguHvSo4jl+wjnKwFpapx+vUDcawbwPNuBIAYdRAvIDBfZVvXprIj3HA+Ugw==",
      "cpu": [
        "ia32"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-loong64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.2.tgz",
      "integrity": "sha512-CN9AZr8kEndGooS35ntToZLTQLHEjtVB5n7dl8ZcTZMonJ7CCfStrYhrzF97eAecqVbVJ7APOEe18RPI4KLhwQ==",
      "cpu": [
        "loong64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-mips64el": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.2.tgz",
      "integrity": "sha512-iMkk7qr/wl3exJATwkISxI7kTcmHKE+BlymIAbHO8xanq/TjHaaVThFF6ipWzPHryoFsesNQJPE/3wFJw4+huw==",
      "cpu": [
        "mips64el"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-ppc64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.2.tgz",
      "integrity": "sha512-shsVrgCZ57Vr2L8mm39kO5PPIb+843FStGt7sGGoqiiWYconSxwTiuswC1VJZLCjNiMLAMh34jg4VSEQb+iEbw==",
      "cpu": [
        "ppc64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-riscv64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.2.tgz",
      "integrity": "sha512-4eSFWnU9Hhd68fW16GD0TINewo1L6dRrB+oLNNbYyMUAeOD2yCK5KXGK1GH4qD/kT+bTEXjsyTCiJGHPZ3eM9Q==",
      "cpu": [
        "riscv64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-s390x": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.2.tgz",
      "integrity": "sha512-S0Bh0A53b0YHL2XEXC20bHLuGMOhFDO6GN4b3YjRLK//Ep3ql3erpNcPlEFed93hsQAjAQDNsvcK+hV90FubSw==",
      "cpu": [
        "s390x"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/linux-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz",
      "integrity": "sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/netbsd-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.24.2.tgz",
      "integrity": "sha512-wuLK/VztRRpMt9zyHSazyCVdCXlpHkKm34WUyinD2lzK07FAHTq0KQvZZlXikNWkDGoT6x3TD51jKQ7gMVpopw==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "netbsd"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/netbsd-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.2.tgz",
      "integrity": "sha512-VefFaQUc4FMmJuAxmIHgUmfNiLXY438XrL4GDNV1Y1H/RW3qow68xTwjZKfj/+Plp9NANmzbH5R40Meudu8mmw==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "netbsd"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/openbsd-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.2.tgz",
      "integrity": "sha512-YQbi46SBct6iKnszhSvdluqDmxCJA+Pu280Av9WICNwQmMxV7nLRHZfjQzwbPs3jeWnuAhE9Jy0NrnJ12Oz+0A==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "openbsd"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/openbsd-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.2.tgz",
      "integrity": "sha512-+iDS6zpNM6EnJyWv0bMGLWSWeXGN/HTaF/LXHXHwejGsVi+ooqDfMCCTerNFxEkM3wYVcExkeGXNqshc9iMaOA==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "openbsd"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/sunos-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.2.tgz",
      "integrity": "sha512-hTdsW27jcktEvpwNHJU4ZwWFGkz2zRJUz8pvddmXPtXDzVKTTINmlmga3ZzwcuMpUvLw7JkLy9QLKyGpD2Yxig==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "sunos"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/win32-arm64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.2.tgz",
      "integrity": "sha512-LihEQ2BBKVFLOC9ZItT9iFprsE9tqjDjnbulhHoFxYQtQfai7qfluVODIYxt1PgdoyQkz23+01rzwNwYfutxUQ==",
      "cpu": [
        "arm64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "win32"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/win32-ia32": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.2.tgz",
      "integrity": "sha512-q+iGUwfs8tncmFC9pcnD5IvRHAzmbwQ3GPS5/ceCyHdjXubwQWI12MKWSNSMYLJMq23/IUCvJMS76PDqXe1fxA==",
      "cpu": [
        "ia32"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "win32"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/@esbuild/win32-x64": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.2.tgz",
      "integrity": "sha512-7VTgWzgMGvup6aSqDPLiW5zHaxYJGTO4OokMjIlrCtf+VpEL+cXKtCvg723iguPYI5oaUNdS+/V7OU2gvXVWEg==",
      "cpu": [
        "x64"
      ],
      "dev": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "win32"
      ],
      "engines": {
        "node": ">=18"
      }
    },
    "node_modules/aws-cdk": {
      "version": "2.175.1",
      "resolved": "https://registry.npmjs.org/aws-cdk/-/aws-cdk-2.175.1.tgz",
      "integrity": "sha512-duvy0FtGAAYqJi/x0MjBfCp60ZlDYl0X5/GrADwMz4AfHQ8aTXCyaVsdJuCxz0ZMHSNaFRuCNkAlc2Xu43zQmQ==",
      "dev": true,
      "license": "Apache-2.0",
      "bin": {
        "cdk": "bin/cdk"
      },
      "engines": {
        "node": ">= 14.15.0"
      },
      "optionalDependencies": {
        "fsevents": "2.3.2"
      }
    },
    "node_modules/aws-cdk-lib": {
      "version": "2.175.1",
      "resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.175.1.tgz",
      "integrity": "sha512-2OiZDUeuAA5nBrWKxQVT0CHrQmLLx7SIpUeqyKRLEdiYPFlj3nCd/0KcVpsy6hPKS+IZp7Qm1kghmGMsV6JGoA==",
      "bundleDependencies": [
        "@balena/dockerignore",
        "case",
        "fs-extra",
        "ignore",
        "jsonschema",
        "minimatch",
        "punycode",
        "semver",
        "table",
        "yaml",
        "mime-types"
      ],
      "license": "Apache-2.0",
      "dependencies": {
        "@aws-cdk/asset-awscli-v1": "^2.2.208",
        "@aws-cdk/asset-kubectl-v20": "^2.1.3",
        "@aws-cdk/asset-node-proxy-agent-v6": "^2.1.0",
        "@aws-cdk/cloud-assembly-schema": "^39.0.1",
        "@balena/dockerignore": "^1.0.2",
        "case": "1.6.3",
        "fs-extra": "^11.2.0",
        "ignore": "^5.3.2",
        "jsonschema": "^1.4.1",
        "mime-types": "^2.1.35",
        "minimatch": "^3.1.2",
        "punycode": "^2.3.1",
        "semver": "^7.6.3",
        "table": "^6.8.2",
        "yaml": "1.10.2"
      },
      "engines": {
        "node": ">= 14.15.0"
      },
      "peerDependencies": {
        "constructs": "^10.0.0"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/@balena/dockerignore": {
      "version": "1.0.2",
      "inBundle": true,
      "license": "Apache-2.0"
    },
    "node_modules/aws-cdk-lib/node_modules/ajv": {
      "version": "8.17.1",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "fast-deep-equal": "^3.1.3",
        "fast-uri": "^3.0.1",
        "json-schema-traverse": "^1.0.0",
        "require-from-string": "^2.0.2"
      },
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/epoberezkin"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/ansi-regex": {
      "version": "5.0.1",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/ansi-styles": {
      "version": "4.3.0",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "color-convert": "^2.0.1"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/astral-regex": {
      "version": "2.0.0",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/balanced-match": {
      "version": "1.0.2",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/brace-expansion": {
      "version": "1.1.11",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/case": {
      "version": "1.6.3",
      "inBundle": true,
      "license": "(MIT OR GPL-3.0-or-later)",
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/color-convert": {
      "version": "2.0.1",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "color-name": "~1.1.4"
      },
      "engines": {
        "node": ">=7.0.0"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/color-name": {
      "version": "1.1.4",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/concat-map": {
      "version": "0.0.1",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/emoji-regex": {
      "version": "8.0.0",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/fast-deep-equal": {
      "version": "3.1.3",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/fast-uri": {
      "version": "3.0.3",
      "inBundle": true,
      "license": "BSD-3-Clause"
    },
    "node_modules/aws-cdk-lib/node_modules/fs-extra": {
      "version": "11.2.0",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=14.14"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/graceful-fs": {
      "version": "4.2.11",
      "inBundle": true,
      "license": "ISC"
    },
    "node_modules/aws-cdk-lib/node_modules/ignore": {
      "version": "5.3.2",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">= 4"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/is-fullwidth-code-point": {
      "version": "3.0.0",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/json-schema-traverse": {
      "version": "1.0.0",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/jsonfile": {
      "version": "6.1.0",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/jsonschema": {
      "version": "1.4.1",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": "*"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/lodash.truncate": {
      "version": "4.4.2",
      "inBundle": true,
      "license": "MIT"
    },
    "node_modules/aws-cdk-lib/node_modules/mime-db": {
      "version": "1.52.0",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/mime-types": {
      "version": "2.1.35",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "mime-db": "1.52.0"
      },
      "engines": {
        "node": ">= 0.6"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/minimatch": {
      "version": "3.1.2",
      "inBundle": true,
      "license": "ISC",
      "dependencies": {
        "brace-expansion": "^1.1.7"
      },
      "engines": {
        "node": "*"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/punycode": {
      "version": "2.3.1",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/require-from-string": {
      "version": "2.0.2",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/semver": {
      "version": "7.6.3",
      "inBundle": true,
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/slice-ansi": {
      "version": "4.0.0",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^4.0.0",
        "astral-regex": "^2.0.0",
        "is-fullwidth-code-point": "^3.0.0"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/slice-ansi?sponsor=1"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/string-width": {
      "version": "4.2.3",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "emoji-regex": "^8.0.0",
        "is-fullwidth-code-point": "^3.0.0",
        "strip-ansi": "^6.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/strip-ansi": {
      "version": "6.0.1",
      "inBundle": true,
      "license": "MIT",
      "dependencies": {
        "ansi-regex": "^5.0.1"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/table": {
      "version": "6.8.2",
      "inBundle": true,
      "license": "BSD-3-Clause",
      "dependencies": {
        "ajv": "^8.0.1",
        "lodash.truncate": "^4.4.2",
        "slice-ansi": "^4.0.0",
        "string-width": "^4.2.3",
        "strip-ansi": "^6.0.1"
      },
      "engines": {
        "node": ">=10.0.0"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/universalify": {
      "version": "2.0.1",
      "inBundle": true,
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    },
    "node_modules/aws-cdk-lib/node_modules/yaml": {
      "version": "1.10.2",
      "inBundle": true,
      "license": "ISC",
      "engines": {
        "node": ">= 6"
      }
    },
    "node_modules/colorette": {
      "version": "2.0.19",
      "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.19.tgz",
      "integrity": "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==",
      "license": "MIT"
    },
    "node_modules/commander": {
      "version": "10.0.1",
      "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz",
      "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==",
      "license": "MIT",
      "engines": {
        "node": ">=14"
      }
    },
    "node_modules/constructs": {
      "version": "10.4.2",
      "resolved": "https://registry.npmjs.org/constructs/-/constructs-10.4.2.tgz",
      "integrity": "sha512-wsNxBlAott2qg8Zv87q3eYZYgheb9lchtBfjHzzLHtXbttwSrHPs1NNQbBrmbb1YZvYg2+Vh0Dor76w4mFxJkA==",
      "license": "Apache-2.0"
    },
    "node_modules/debug": {
      "version": "4.3.4",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
      "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
      "license": "MIT",
      "dependencies": {
        "ms": "2.1.2"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/esbuild": {
      "version": "0.24.2",
      "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz",
      "integrity": "sha512-+9egpBW8I3CD5XPe0n6BfT5fxLzxrlDzqydF3aviG+9ni1lDC/OvMHcxqEFV0+LANZG5R1bFMWfUrjVsdwxJvA==",
      "dev": true,
      "hasInstallScript": true,
      "license": "MIT",
      "bin": {
        "esbuild": "bin/esbuild"
      },
      "engines": {
        "node": ">=18"
      },
      "optionalDependencies": {
        "@esbuild/aix-ppc64": "0.24.2",
        "@esbuild/android-arm": "0.24.2",
        "@esbuild/android-arm64": "0.24.2",
        "@esbuild/android-x64": "0.24.2",
        "@esbuild/darwin-arm64": "0.24.2",
        "@esbuild/darwin-x64": "0.24.2",
        "@esbuild/freebsd-arm64": "0.24.2",
        "@esbuild/freebsd-x64": "0.24.2",
        "@esbuild/linux-arm": "0.24.2",
        "@esbuild/linux-arm64": "0.24.2",
        "@esbuild/linux-ia32": "0.24.2",
        "@esbuild/linux-loong64": "0.24.2",
        "@esbuild/linux-mips64el": "0.24.2",
        "@esbuild/linux-ppc64": "0.24.2",
        "@esbuild/linux-riscv64": "0.24.2",
        "@esbuild/linux-s390x": "0.24.2",
        "@esbuild/linux-x64": "0.24.2",
        "@esbuild/netbsd-arm64": "0.24.2",
        "@esbuild/netbsd-x64": "0.24.2",
        "@esbuild/openbsd-arm64": "0.24.2",
        "@esbuild/openbsd-x64": "0.24.2",
        "@esbuild/sunos-x64": "0.24.2",
        "@esbuild/win32-arm64": "0.24.2",
        "@esbuild/win32-ia32": "0.24.2",
        "@esbuild/win32-x64": "0.24.2"
      }
    },
    "node_modules/escalade": {
      "version": "3.2.0",
      "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
      "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/esm": {
      "version": "3.2.25",
      "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
      "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/fsevents": {
      "version": "2.3.2",
      "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
      "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
      "dev": true,
      "hasInstallScript": true,
      "license": "MIT",
      "optional": true,
      "os": [
        "darwin"
      ],
      "engines": {
        "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/get-package-type": {
      "version": "0.1.0",
      "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz",
      "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==",
      "license": "MIT",
      "engines": {
        "node": ">=8.0.0"
      }
    },
    "node_modules/getopts": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/getopts/-/getopts-2.3.0.tgz",
      "integrity": "sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==",
      "license": "MIT"
    },
    "node_modules/hasown": {
      "version": "2.0.2",
      "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
      "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
      "license": "MIT",
      "dependencies": {
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/interpret": {
      "version": "2.2.0",
      "resolved": "https://registry.npmjs.org/interpret/-/interpret-2.2.0.tgz",
      "integrity": "sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.10"
      }
    },
    "node_modules/is-core-module": {
      "version": "2.16.1",
      "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz",
      "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==",
      "license": "MIT",
      "dependencies": {
        "hasown": "^2.0.2"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/knex": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/knex/-/knex-3.1.0.tgz",
      "integrity": "sha512-GLoII6hR0c4ti243gMs5/1Rb3B+AjwMOfjYm97pu0FOQa7JH56hgBxYf5WK2525ceSbBY1cjeZ9yk99GPMB6Kw==",
      "license": "MIT",
      "dependencies": {
        "colorette": "2.0.19",
        "commander": "^10.0.0",
        "debug": "4.3.4",
        "escalade": "^3.1.1",
        "esm": "^3.2.25",
        "get-package-type": "^0.1.0",
        "getopts": "2.3.0",
        "interpret": "^2.2.0",
        "lodash": "^4.17.21",
        "pg-connection-string": "2.6.2",
        "rechoir": "^0.8.0",
        "resolve-from": "^5.0.0",
        "tarn": "^3.0.2",
        "tildify": "2.0.0"
      },
      "bin": {
        "knex": "bin/cli.js"
      },
      "engines": {
        "node": ">=16"
      },
      "peerDependenciesMeta": {
        "better-sqlite3": {
          "optional": true
        },
        "mysql": {
          "optional": true
        },
        "mysql2": {
          "optional": true
        },
        "pg": {
          "optional": true
        },
        "pg-native": {
          "optional": true
        },
        "sqlite3": {
          "optional": true
        },
        "tedious": {
          "optional": true
        }
      }
    },
    "node_modules/lodash": {
      "version": "4.17.21",
      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
      "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
      "license": "MIT"
    },
    "node_modules/ms": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
      "license": "MIT"
    },
    "node_modules/path-parse": {
      "version": "1.0.7",
      "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
      "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
      "license": "MIT"
    },
    "node_modules/pg-connection-string": {
      "version": "2.6.2",
      "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.2.tgz",
      "integrity": "sha512-ch6OwaeaPYcova4kKZ15sbJ2hKb/VP48ZD2gE7i1J+L4MspCtBMAx8nMgz7bksc7IojCIIWuEhHibSMFH8m8oA==",
      "license": "MIT"
    },
    "node_modules/rechoir": {
      "version": "0.8.0",
      "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz",
      "integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==",
      "license": "MIT",
      "dependencies": {
        "resolve": "^1.20.0"
      },
      "engines": {
        "node": ">= 10.13.0"
      }
    },
    "node_modules/resolve": {
      "version": "1.22.10",
      "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz",
      "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==",
      "license": "MIT",
      "dependencies": {
        "is-core-module": "^2.16.0",
        "path-parse": "^1.0.7",
        "supports-preserve-symlinks-flag": "^1.0.0"
      },
      "bin": {
        "resolve": "bin/resolve"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/resolve-from": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
      "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/supports-preserve-symlinks-flag": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
      "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/tarn": {
      "version": "3.0.2",
      "resolved": "https://registry.npmjs.org/tarn/-/tarn-3.0.2.tgz",
      "integrity": "sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8.0.0"
      }
    },
    "node_modules/tildify": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/tildify/-/tildify-2.0.0.tgz",
      "integrity": "sha512-Cc+OraorugtXNfs50hU9KS369rFXCfgGLpfCfvlc+Ud5u6VWmUQsOAa9HbTvheQdYnrdJqqv1e5oIqXppMYnSw==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    }
  }
}

Run npx cdk synth to reproduce the issue.

ben-eb avatar Jan 15 '25 09:01 ben-eb

Adding to Abstractions project for team's input.

ashishdhingra avatar Feb 03 '25 22:02 ashishdhingra

hi @ben-eb , Thanks for reporting this. Can you describe the module loading issue? From the files you have, looks like its the target state with type:"module" in package.json.

We need a bit of help understand the issue you are facing.

QuantumNeuralCoder avatar Feb 26 '25 22:02 QuantumNeuralCoder

It's difficult for me to produce a reduced test case here (and the code is closed source). When trying to think about the problem in terms of dynamic imports I ran into another issue that I don't think I was seeing when I raised this one:

When compiling this source code (via cdk synth) it seems that the CDK library is imported into the bundle but only when using the .js extension:

src/index.js

export async function handler() {
    const { init } = await getImplementation();

    return init();
}

async function getImplementation() {
    const { IMPLEMENTATION } = process.env;

    if (IMPLEMENTATION !== 'a' && IMPLEMENTATION !== 'b') {
        throw new Error('Expected "IMPLEMENTATION" to be either a or b');
    }

    return await import(`./${IMPLEMENTATION}.js`);
}

src/a.js

export function init() {
    return 'Hello from A';
}

src/b.js

export function init() {
    return 'Hello from B';
}

src/stack.js

import * as path from 'node:path';
import url from 'node:url';
import * as cdk from 'aws-cdk-lib';
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
import * as Lambda from 'aws-cdk-lib/aws-lambda';

export class InfrastructureStack extends cdk.Stack {
    constructor(scope, id) {
        super(scope, id);

        const banner =
            "const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);";

        const root = url.fileURLToPath(new URL('.', import.meta.url));

        const externalModules = ['a.js', 'b.js'];

        new NodejsFunction(this, 'lambda', {
            functionName: 'test-knex-esm',
            entry: path.join(root, 'index.js'),
            runtime: Lambda.Runtime.NODEJS_20_X,
            environment: {
                IMPLEMENTATION: 'a'
            },
            bundling: {
                banner,
                format: OutputFormat.ESM,
                mainFields: ['module', 'main'],
                nodeModules: ['knex'],
                externalModules,
                commandHooks: {
                    beforeBundling(inputDir, outputDir) {
                        return [];
                    },
                    beforeInstall(inputDir, outputDir) {
                        return [];
                    },
                    afterBundling(inputDir, outputDir) {
                        return externalModules.map(
                            (file) => `cp ${path.join(root, file)} ${outputDir}`
                        );
                    },
                },
            },
        });
    }
}

The generated bundle comes out at a whopping 43 MB and times out when executing on Lambda.

However if we change the externalModules to ['a.mjs', 'b.mjs'] the CDK library is no longer bundled and the function executes normally. We can also change the IMPLEMENTATION variable on Lambda to b and the module is picked up properly.

ben-eb avatar Feb 27 '25 10:02 ben-eb

We are experimenting with an alternative way of bundling. We would very much appreciate any feedback you can give and let us know if this would solve your issues. Sample app

QuantumNeuralCoder avatar Mar 03 '25 18:03 QuantumNeuralCoder