npm / npm/cli

[BUG] $EDITOR environment variable broken on Windows

Open
#6,716 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

On Windows, if the EDITOR environment variable is set, npm config edit does not resolve it as either a literal path nor a shell command.

Expected Behavior

I expect either:

  1. Editor to be a path to an executable
  2. Normal shell-like resolution applies to the command (including escaping spaces)
Steps To Reproduce
  1. On windows 11, using PowerShell or the Environment Variable Editor, set the value of EDITOR
  2. Call npm config edit
  • If the value of EDITOR has a space in it, it is truncated there (even if the executable is surrounded by ", meaning you can't use a path with a space in it. None of the following work:
# any of the below values
$env:EDITOR=(gcm code).source
$env:EDITOR="C:\Users\dan\AppData\Local\Programs\Microsoft VS Code\bin\code"
$env:EDITOR='"C:\Users\dan\AppData\Local\Programs\Microsoft VS Code\bin\code"'
$env:EDITOR="C:\Users\dan\AppData\Local\Programs\Microsoft^ VS^ Code\bin\code"
npm config edit

The error message indicates that the path is truncated at the first space, e.g.

npm config edit
npm ERR! code ENOENT
npm ERR! syscall spawn C:\Users\dan\AppData\Local\Programs\Microsoft
npm ERR! path C:\Users\dan\AppData\Local\Programs\Microsoft
npm ERR! errno -4058
npm ERR! enoent spawn C:\Users\dan\AppData\Local\Programs\Microsoft ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

  • normal shell resolution of a command does not work:
$env:EDITOR="code"
  • The following does work:
$env:EDITOR="code.cmd"
Environment
  • npm: 9.8.1
  • Node.js: v18.17.1
  • OS Name: Windows 11
  • System Model Name:
  • npm config:
npm config ls
; "builtin" config from C:\Users\dan\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\dan\\AppData\\Roaming\\npm"

; "user" config from C:\Users\dan\.npmrc

@cs:registry = "http://reg.example.com"
//registry.npmjs.org/:_authToken = (protected)

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.17.1
; npm local prefix = C:\Users\dan\Source\Cerulean\SonarView
; npm version = 9.8.1
; cwd = C:\Users\dan\Source\Cerulean\SonarView
; HOME = C:\Users\dan
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing npm config edit on Windows with EDITOR set to a path containing spaces and to code, then compare it with the working code.cmd case. Trace the npm config edit entry point and the editor process launch; done means executable paths with spaces and normal shell-like command resolution both work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.