diff --git a/src/NextjsAssetsDeployment.ts b/src/NextjsAssetsDeployment.ts index f3227df7..f00448f8 100644 --- a/src/NextjsAssetsDeployment.ts +++ b/src/NextjsAssetsDeployment.ts @@ -128,6 +128,7 @@ export class NextJsAssetsDeployment extends Construct { compressionLevel: this.props.compressionLevel, quiet: this.props.quiet, }); + if (!archiveZipFilePath) return []; const deployment = new BucketDeployment(this, 'NextStaticAssetsS3Deployment', { destinationBucket: this.bucket, diff --git a/src/NextjsBuild.ts b/src/NextjsBuild.ts index 6e7cdb1f..00a1d7cd 100644 --- a/src/NextjsBuild.ts +++ b/src/NextjsBuild.ts @@ -183,7 +183,10 @@ export function createArchive({ fileGlob = '*', compressionLevel = 1, quiet, -}: CreateArchiveArgs): string { +}: CreateArchiveArgs): string | null { + // if directory is empty, can skip + if (!fs.existsSync(directory) || fs.readdirSync(directory).length === 0) return null; + zipOutDir = path.resolve(zipOutDir); fs.mkdirpSync(zipOutDir); // get output path diff --git a/src/NextjsLambda.ts b/src/NextjsLambda.ts index c222a620..c6dd0cbc 100644 --- a/src/NextjsLambda.ts +++ b/src/NextjsLambda.ts @@ -91,6 +91,7 @@ export class NextJsLambda extends Construct { fileGlob: '*', quiet: props.quiet, }); + if (!zipFilePath) throw new Error('Failed to create archive for lambda function code'); // build native deps layer const nextLayer = new NextjsLayer(scope, 'NextjsLayer', {});