Skip to content

Commit 45e9e67

Browse files
authoredMar 12, 2025··
fix: ignore @img in copyTracedFiles (#769)
* fix: ignore @img/* in copyTracedFiles * changeset * review * getCrossPlatformPathRegex and str.match
1 parent 068ce66 commit 45e9e67

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed
 

‎.changeset/tall-pets-hammer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
Fix: Ignore packages under the @img/\* scope to exclude sharp from the server bundle.

‎packages/open-next/src/build/copyTracedFiles.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,27 @@ import {
1414
import path from "node:path";
1515

1616
import { loadConfig, loadPrerenderManifest } from "config/util.js";
17+
import { getCrossPlatformPathRegex } from "utils/regex.js";
1718
import logger from "../logger.js";
1819
import { MIDDLEWARE_TRACE_FILE } from "./constant.js";
1920

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

23+
//TODO: we need to figure which packages we could safely remove
24+
const EXCLUDED_PACKAGES = [
25+
"caniuse-lite",
26+
"sharp",
27+
// This seems to be only in Next 15
28+
// Some of sharp deps are under the @img scope
29+
"@img",
30+
];
31+
32+
function isExcluded(srcPath: string) {
33+
return EXCLUDED_PACKAGES.some((excluded) =>
34+
srcPath.match(getCrossPlatformPathRegex(`/node_modules/${excluded}/`)),
35+
);
36+
}
37+
2238
function copyPatchFile(outputDir: string) {
2339
const patchFile = path.join(__dirname, "patch", "patchedAsyncStorage.js");
2440
const outputPatchFile = path.join(outputDir, "patchedAsyncStorage.cjs");
@@ -194,12 +210,8 @@ File ${fullFilePath} does not exist
194210

195211
//Actually copy the files
196212
filesToCopy.forEach((to, from) => {
197-
if (
198-
//TODO: we need to figure which packages we could safely remove
199-
from.includes(path.join("node_modules", "caniuse-lite")) ||
200-
// from.includes("jest-worker") || This ones seems necessary for next 12
201-
from.includes(path.join("node_modules", "sharp"))
202-
) {
213+
// We don't want to copy excluded packages (i.e sharp)
214+
if (isExcluded(from)) {
203215
return;
204216
}
205217
mkdirSync(path.dirname(to), { recursive: true });

0 commit comments

Comments
 (0)
Please sign in to comment.