Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-pets-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

Fix: Ignore packages under the @img/\* scope to exclude sharp from the server bundle.
25 changes: 19 additions & 6 deletions packages/open-next/src/build/copyTracedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ import { MIDDLEWARE_TRACE_FILE } from "./constant.js";

const __dirname = url.fileURLToPath(new URL(".", import.meta.url));

//TODO: we need to figure which packages we could safely remove
const EXCLUDED_PACKAGES = [
"caniuse-lite",
"sharp",
// This seems to be only in Next 15
// Some of sharp deps are under the @img scope
"@img",
];

function isExcluded(srcPath: string) {
return EXCLUDED_PACKAGES.some((excluded) =>
new RegExp(`${path.sep}node_modules${path.sep}${excluded}${path.sep}`).test(
srcPath,
),
);
}

function copyPatchFile(outputDir: string) {
const patchFile = path.join(__dirname, "patch", "patchedAsyncStorage.js");
const outputPatchFile = path.join(outputDir, "patchedAsyncStorage.cjs");
Expand Down Expand Up @@ -194,12 +211,8 @@ File ${fullFilePath} does not exist

//Actually copy the files
filesToCopy.forEach((to, from) => {
if (
//TODO: we need to figure which packages we could safely remove
from.includes(path.join("node_modules", "caniuse-lite")) ||
// from.includes("jest-worker") || This ones seems necessary for next 12
from.includes(path.join("node_modules", "sharp"))
) {
// We don't want to copy excluded packages (i.e sharp)
if (isExcluded(from)) {
return;
}
mkdirSync(path.dirname(to), { recursive: true });
Expand Down
Loading