Skip to content

Conversation

@polyomino24
Copy link
Contributor

Context / Background

While running corepack enable without sudo in a CircleCI docker environment(cimg/node:22.20.0), the build failed with an EACCES: permission denied, unlink '/usr/local/bin/pnpm' error.

This error was caused by the recent change #761 from readlink to realpath in generatePosixLink.

https://github.com/nodejs/corepack/pull/761/files#diff-c91b034b85c9610409bf66de5d28560a06f1285ee1962f238fac2c3652a15e88L86-R88

Problem

Using fs.promises.realpath in generatePosixLink returns the fully resolved, absolute path of the symlink target.

However, the symlink variable used in the comparison is a relative path calculated by path.relative. This results in a comparison between an absolute path and a relative path, causing the currentSymlink !== symlink check to always evaluate to true.

const symlink = path.relative(installDirectory, path.join(distFolder, `${binName}.js`));
if (fs.existsSync(file)) {
const currentSymlink = await fs.promises.realpath(file);
if (binName.includes(`yarn`) && corepackUtils.isYarnSwitchPath(currentSymlink)) {
console.warn(`${binName} is already installed in ${file} and points to a Yarn Switch install - skipping`);
return;
}
if (currentSymlink !== symlink) {
await fs.promises.unlink(file);
} else {
return;
}
}

@polyomino24 polyomino24 requested a review from aduh95 November 10, 2025 11:27
- add expected stdout & stderr
- use Node.js async setTimeout
- add --install-directory option
@polyomino24 polyomino24 requested a review from aduh95 November 11, 2025 01:34
@polyomino24 polyomino24 requested a review from aduh95 November 14, 2025 09:27
@aduh95 aduh95 enabled auto-merge (squash) November 14, 2025 09:32
@polyomino24
Copy link
Contributor Author

@aduh95
Could you please re-run the failed tests?

@aduh95 aduh95 merged commit a02bea0 into nodejs:main Nov 14, 2025
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants