aws-lambda-nodejs-esbuild
raw JSON → 1.1.6 verified Fri May 01 auth: no javascript maintenance
AWS CDK Construct for bundling Node.js AWS Lambda functions using esbuild. Version 1.1.6 (latest) supports zero-config bundling with ESNext/TypeScript, automatic package manager detection, and external module support. Unlike @aws-cdk/aws-lambda-nodejs (which uses esbuild internally but with less configurability), this construct exposes full esbuild options and allows overriding the 'exclude' list. Currently in maintenance mode; designed for CDK v1 and lacks native CDK v2 support.
Common errors
error Error: Cannot find module 'esbuild' ↓
cause esbuild is not installed in the project
fix
npm install --save-dev esbuild
error Error: Cannot find module '@aws-cdk/aws-lambda' ↓
cause CDK peer dependencies not installed
fix
npm install --save @aws-cdk/aws-lambda @aws-cdk/core
error Property 'entry' is missing in type 'NodejsFunctionProps' ↓
cause The 'entry' property is required for NodejsFunction but omitted
fix
Add 'entry' to the props: entry: 'src/index.ts'
Warnings
deprecated Package is designed for AWS CDK v1 and not updated for CDK v2 ↓
fix For CDK v2, use @aws-cdk/aws-lambda-nodejs built-in bundling or migrate to a CDK v2 compatible construct
gotcha esbuild must be installed separately in the project; not a dependency of this package ↓
fix Run 'npm install --save-dev esbuild' or 'yarn add --dev esbuild'
gotcha The default 'exclude' option only excludes 'aws-sdk'; other large dependencies must be manually externalized ↓
fix Add additional modules to esbuildOptions.external: e.g., external: ['aws-sdk', 'pg-native']
breaking Version 1.1.6 changed default runtime to match CDK Lambda defaults; may affect previously working builds ↓
fix Explicitly set runtime property on NodejsFunction to avoid reliance on default
Install
npm install aws-lambda-nodejs-esbuild yarn add aws-lambda-nodejs-esbuild pnpm add aws-lambda-nodejs-esbuild Imports
- NodejsFunction wrong
const { NodejsFunction } = require('aws-lambda-nodejs-esbuild')correctimport { NodejsFunction } from 'aws-lambda-nodejs-esbuild' - NodejsFunctionProps
import { NodejsFunctionProps } from 'aws-lambda-nodejs-esbuild' - default wrong
import AWS from 'aws-lambda-nodejs-esbuild'correctimport AWS from 'aws-lambda-nodejs-esbuild'
Quickstart
import * as cdk from '@aws-cdk/core';
import { NodejsFunction } from 'aws-lambda-nodejs-esbuild';
import { Runtime } from '@aws-cdk/aws-lambda';
class MyStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new NodejsFunction(this, 'MyLambda', {
entry: 'src/handler.ts',
runtime: Runtime.NODEJS_14_X,
esbuildOptions: {
minify: true,
target: 'ES2017',
external: ['aws-sdk'],
},
});
}
}
const app = new cdk.App();
new MyStack(app, 'MyStack');