From 03813e13a3b3be3eb5e1c3c91d561bed2c393242 Mon Sep 17 00:00:00 2001 From: Tommaso De Rossi Date: Thu, 1 Sep 2022 20:20:08 +0200 Subject: [PATCH] ignore EEXIST errors when creating symlinks for output standalone (#40150) I think the `EEXIST` error may be because next already copies some files here https://github.com/vercel/next.js/blob/e91cbcc03d7226cc6f2edb66c656ae08bdf5b903/packages/next/build/index.ts#L2442 partially fixes #36386 when using pnpm linker ## Bug - [x] Related issues linked using - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` --- packages/next/build/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/next/build/utils.ts b/packages/next/build/utils.ts index c050e89d49cb..e5cdc0f93929 100644 --- a/packages/next/build/utils.ts +++ b/packages/next/build/utils.ts @@ -1371,7 +1371,13 @@ export async function copyTracedFiles( const symlink = await fs.readlink(tracedFilePath).catch(() => null) if (symlink) { - await fs.symlink(symlink, fileOutputPath) + try { + await fs.symlink(symlink, fileOutputPath) + } catch (e: any) { + if (e.code !== 'EEXIST') { + throw e + } + } } else { await fs.copyFile(tracedFilePath, fileOutputPath) }