diff --git a/.changeset/beige-ways-switch.md b/.changeset/beige-ways-switch.md new file mode 100644 index 000000000..5a58c6620 --- /dev/null +++ b/.changeset/beige-ways-switch.md @@ -0,0 +1,12 @@ +--- +"@opennextjs/aws": patch +--- + +chore: Exclude more packages + +Added a debug to determine which packages that gets excluded from the final bundle's `node_modules`. Will skip these packages now aswell: + +- "typescript" +- "next/dist/compiled/babel" +- "next/dist/compiled/babel-packages" +- "next/dist/compiled/amphtml-validator" \ No newline at end of file diff --git a/packages/open-next/src/build/copyTracedFiles.ts b/packages/open-next/src/build/copyTracedFiles.ts index e82b59e25..4cbaab80d 100644 --- a/packages/open-next/src/build/copyTracedFiles.ts +++ b/packages/open-next/src/build/copyTracedFiles.ts @@ -39,10 +39,14 @@ const EXCLUDED_PACKAGES = [ // This seems to be only in Next 15 // Some of sharp deps are under the @img scope "@img", + "typescript", + "next/dist/compiled/babel", + "next/dist/compiled/babel-packages", + "next/dist/compiled/amphtml-validator", ]; -function isExcluded(srcPath: string) { - return EXCLUDED_PACKAGES.some((excluded) => +function isExcluded(srcPath: string): string | undefined { + return EXCLUDED_PACKAGES.find((excluded) => srcPath.match(getCrossPlatformPathRegex(`/node_modules/${excluded}/`)), ); } @@ -250,11 +254,17 @@ File ${serverPath} does not exist // Only files that are actually copied const tracedFiles: string[] = []; - + // Packages that are excluded and not copied + const excludedPackages = new Set(); //Actually copy the files filesToCopy.forEach((to, from) => { - // We don't want to copy excluded packages (i.e sharp) - if (isExcluded(from)) { + // We don't want to copy excluded packages (e.g. sharp) + const excluded = isExcluded(from); + if (excluded) { + if (excluded && !excludedPackages.has(excluded)) { + logger.debug("Skipping excluded package:", excluded); + excludedPackages.add(excluded); + } return; } tracedFiles.push(to);