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

fix(installDeps): Ensure symlinks are dereferenced on all Node versions

Upstream issue in Node: https://github.com/nodejs/node/issues/59168
39 changes: 18 additions & 21 deletions packages/open-next/src/build/installDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { InstallOptions } from "types/open-next";

import logger from "../logger.js";

const AFFECTED_NODE_VERSIONS = ["22.17.0", "22.17.1", "22.18.0"];

export function installDependencies(
outputDir: string,
installOptions?: InstallOptions,
Expand Down Expand Up @@ -54,33 +52,32 @@ export function installDependencies(
{ recursive: true, force: true, dereference: true },
);

// This is a workaround for Node `22.17.0` and `22.17.1`
// https://github.com/nodejs/node/issues/59168
const nodeVersion = process.versions.node;
if (AFFECTED_NODE_VERSIONS.includes(nodeVersion)) {
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);
// This is a workaround for all Node versions. It seems to be an issue continue to affect new versions aswell.
// Therefor I think the most logical solution is to always run this workaround instead of trying to figure out which versions are affected.
const tempBinDir = path.join(tempInstallDir, "node_modules", ".bin");
const outputBinDir = path.join(outputDir, "node_modules", ".bin");

if (stat.isSymbolicLink()) {
const linkTarget = fs.readlinkSync(symlinkPath);
const realFilePath = path.resolve(tempBinDir, linkTarget);
for (const fileName of fs.readdirSync(tempBinDir)) {
const symlinkPath = path.join(tempBinDir, fileName);
const stat = fs.lstatSync(symlinkPath);

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

if (fs.existsSync(outputFilePath)) {
fs.unlinkSync(outputFilePath);
}
const outputFilePath = path.join(outputBinDir, fileName);

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

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

// Cleanup tempDir
fs.rmSync(tempInstallDir, { recursive: true, force: true });
Expand Down
Loading