New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pnpm env use --global lts - EPERM: operation not permitted, symlink (Windows 11) #4315
Comments
Same here, need to use administrator privileges to install. |
you'll need to run either |
It's been more than 6 years since you don't need to "Run As Administrator" to create "Symlinks" in windows 10 v10.0.14972 and newer Windows versions - when you have "Developer Mode" enabled. ( Settings > Update and Security > For Developers > toggle on Developer Mode ). |
@mominshaikhdevs Good to know, but is it expected that one must first enable Developer Mode to install pnpm? |
@colinmollenhour Answer to that question will be a no as pnpm uses hardlinks , not symlinks. Hardlinks don't require "Developer Mode". |
I can replicate this on Version 8.2.0 (compiled to binary; bundled Node.js v18.1.0) installed on Windows 10 without admin.
|
I'm digging in the source code and I think I found the culprit.
I think the options are:
The code the rest of pnpm uses for hard linking is here I believe, but it's not exported. pnpm/fs/hard-link-dir/src/index.ts Lines 46 to 72 in ece5a1a
|
The solution is to use the |
Thank you very much for the recommendation. I've tried but I'm running into some issues while testing it. symlink-dir// symlink.js
const symlinkDir = require("symlink-dir");
const src = `C:\\Users\\rihan\\AppData\\Local\\pnpm\\nodejs\\18.15.0\\node.exe`;
const dest = `C:\\Users\\rihan\\AppData\\Local\\pnpm\\node.exe`;
symlinkDir(src, dest).then((testOutput) => console.log(testOutput));
It looks like it's treating node.exe from the source dir as if it's a folder (trailing slash in Is there something I'm missing/doing wrong here? Hard linkingCode// hardlink.mjs
import { promises as fs } from "fs";
const src = `C:\\Users\\rihan\\AppData\\Local\\pnpm\\nodejs\\18.15.0\\node.exe`;
const dest = `C:\\Users\\rihan\\AppData\\Local\\pnpm\\node.exe`;
await linkOrCopyFile(src, dest);
async function linkOrCopyFile(srcFile, destFile) {
try {
await linkOrCopy(srcFile, destFile);
} catch (err) {
// eslint-disable-line
if (err.code === "ENOENT") {
await fs.mkdir(path.dirname(destFile), { recursive: true });
await linkOrCopy(srcFile, destFile);
return;
}
if (err.code !== "EEXIST") {
throw err;
}
}
}
/*
* This function could be optimized because we don't really need to try linking again
* if linking failed once.
*/
async function linkOrCopy(srcFile, destFile) {
try {
await fs.link(srcFile, destFile);
} catch (err) {
// eslint-disable-line
if (err.code !== "EXDEV") throw err;
await fs.copyFile(srcFile, destFile);
}
}
Original behaviourAfter enabling developer mode (requires admin and reduces Windows security)
|
I have added a test for symlinking a file and it seem to work: https://github.com/pnpm/symlink-dir/actions/runs/4690793134/jobs/8314383394 EDIT: no, it fails |
@RihanArfan it appears that junctions only work with directories, so symlink-dir won't work. I guess we may use hard links if they work. |
Thanks @zkochan ! |
pnpm version: 6.30.0 (compiled to binary; bundled Node.js v14.17.0)
Code to reproduce the issue:
PATH did not contain pnpm after launching a new shell, had to run the above twice for some reason?
Expected behavior:
Installs the latest LTS and links it into PATH
Actual behavior:
Additional information:
This is a very clean install of Windows 11 - no previous version of Node or PNPM had ever been installed before.
I ran the same steps in a PowerShell invoked with Run as Administrator and that worked. Is it expected that the installer needs to run as Administrator? If so, I believe this should be noted in the installation guide.
The text was updated successfully, but these errors were encountered: