Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions .changeset/hip-lies-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@opennextjs/aws": patch
---

fix: Workaround for broken symlink dereferencing in Node 22.17.0 and 22.17.1

The `dereference: true` option in `fs.cpSync()` is broken on version 22.17.0 and 22.17.1. This fix will do it manually for the binaries in `node_modules/.bin`. We can revert this once fixed upstream.

Issue in Node: https://github.com/nodejs/node/issues/59168
29 changes: 28 additions & 1 deletion packages/open-next/src/build/installDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,37 @@ export function installDependencies(
fs.cpSync(
path.join(tempInstallDir, "node_modules"),
path.join(outputDir, "node_modules"),

{ recursive: true, force: true, dereference: true },
);

// This is a workaround for Node `22.17.0` and `22.17.1`
// Can remove these lines when this is fixed upstream: https://github.com/nodejs/node/issues/59168
const nodeVersion = process.version;
if (nodeVersion === "v22.17.0" || nodeVersion === "v22.17.1") {
const tempBinDir = path.join(tempInstallDir, "node_modules", ".bin");
const outputBinDir = path.join(outputDir, "node_modules", ".bin");

for (const fileName of fs.readdirSync(tempBinDir)) {
const symlinkPath = path.join(tempBinDir, fileName);
const stat = fs.lstatSync(symlinkPath);

if (stat.isSymbolicLink()) {
const linkTarget = fs.readlinkSync(symlinkPath);
const realFilePath = path.resolve(tempBinDir, linkTarget);

const outputFilePath = path.join(outputBinDir, fileName);

if (fs.existsSync(outputFilePath)) {
fs.unlinkSync(outputFilePath);
}

fs.copyFileSync(realFilePath, outputFilePath);
fs.chmodSync(outputFilePath, "755");
logger.debug(`Replaced symlink ${fileName} with actual file`);
}
}
}

// Cleanup tempDir
fs.rmSync(tempInstallDir, { recursive: true, force: true });
logger.info(`Dependencies installed for ${name}`);
Expand Down
Loading