Skip to content

[BUG] npm install in a workspaces environment requires admin permissions on Windows #1923

@RoystonS

Description

@RoystonS

Current Behavior:

npm install in a workspaces environment fails if the current user is not running under administrator privileges because directory symlinks can't be created on Windows without admin privilege (or some rather non-standard configuration)

Expected Behavior:

npm install would ideally 'just work' on Windows, which could be done by using Windows 'junctions' instead of directory symlinks. These are pretty much the same as directory symlinks but don't require admin permissions.

(This is what yarn does, incidentally. I'd love to be able to move back from yarn to npm, and workspace support is the killer feature for us.)

With the current behaviour, npm 7 workspace support will be broken on Windows unless the user runs as admin or does some non-trivial configuration to enable the creation of directory symlinks. (No, I don't know why Windows requires this hoop-jumping just to make symlinks, but it does. It's grim. But junctions are an easy workaround for it.)

Steps To Reproduce:

  1. Create a simple workspaces environment on Windows
  2. run npm install

See error:

npm ERR! code EPERM
npm ERR! syscall symlink
npm ERR! path ..\..\packages\pkg2
npm ERR! dest C:\Dev\monorepo\node_modules\@my\pkg2
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, symlink '..\..\packages\pkg2' -> 'C:\Dev\monorepo\node_modules\@my\pkg2'npm ERR!  [Error: EPERM: operation not permitted, symlink '..\..\packages\pkg2' -> 'C:\Dev\monorepo\node_modules\@my\pkg2'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '..\\..\\packages\\pkg2',
npm ERR!   dest: 'C:\\Dev\\monorepo\\node_modules\\@my\\pkg2'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

Having to run as administrator isn't a realistic workaround for this sort of scenario; it would cause a lot of extra effort modifying build machines and scripts to be able to switch to administrator mode, and would massively weaken security as a result.

Environment:

OS: Windows 10
Node: 12.18.3
npm: 7.0.0-rc.3

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 releaseplatform:windowsis Windows-specific

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions