@@ -33,8 +33,10 @@ import type { FunctionOptions, SplittedFunctionOptions } from "@opennextjs/aws/t
3333import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js" ;
3434import type { Plugin } from "esbuild" ;
3535
36+ import { getOpenNextConfig } from "../../../api/config.js" ;
3637import { patchResRevalidate } from "../patches/plugins/res-revalidate.js" ;
3738import { normalizePath } from "../utils/index.js" ;
39+ import { copyWorkerdPackages } from "../utils/workerd.js" ;
3840
3941interface CodeCustomization {
4042 // These patches are meant to apply on user and next generated code
@@ -180,14 +182,20 @@ async function generateBundle(
180182 buildHelper . copyEnvFile ( appBuildOutputPath , packagePath , outputPath ) ;
181183
182184 // Copy all necessary traced files
183- const { tracedFiles, manifests } = await copyTracedFiles ( {
185+ const { tracedFiles, manifests, nodePackages } = await copyTracedFiles ( {
184186 buildOutputPath : appBuildOutputPath ,
185187 packagePath,
186188 outputDir : outputPath ,
187189 routes : fnOptions . routes ?? [ "app/page.tsx" ] ,
188190 bundledNextServer : isBundled ,
189191 } ) ;
190192
193+ if ( getOpenNextConfig ( options ) . cloudflare ?. useWorkerdCondition !== false ) {
194+ // Next does not trace the "workerd" build condition
195+ // So we need to copy the whole packages using the condition
196+ await copyWorkerdPackages ( options , nodePackages ) ;
197+ }
198+
191199 const additionalCodePatches = codeCustomization ?. additionalCodePatches ?? [ ] ;
192200
193201 await applyCodePatches ( options , tracedFiles , manifests , [
0 commit comments