coreybutler/nvm-windows · error

error: failed to create backup: %v

Error message

error: failed to create backup: %v

What it means

nvm-windows zips the entire current installation directory into the backup temp dir before applying the new files. This error means zipDirectory failed while walking or writing the current install path — usually a file is locked or unreadable (running nvm.exe itself, node processes spawned from it, antivirus scans) or a path/permission problem inside NVM_HOME. The original installation is still untouched when this fires.

Source

Thrown at src/upgrade/upgrade.go:475

		err = nvmtestcmd.Run()
		if err != nil {
			fmt.Println("error running nvm.exe:", err)
		}
	}

	// Backup current version to zip
	status <- Status{Text: "applying update..."}
	currentExe, _ := os.Executable()
	currentPath := filepath.Dir(currentExe)
	bkp, err := os.MkdirTemp("", "nvm-backup-*")
	if err != nil {
		status <- Status{Err: fmt.Errorf("error: failed to create backup directory: %v\n", err)}
	}
	defer os.RemoveAll(bkp)

	err = zipDirectory(currentPath, filepath.Join(bkp, "backup.zip"))
	if err != nil {
		status <- Status{Err: fmt.Errorf("error: failed to create backup: %v\n", err)}
	}

	os.MkdirAll(filepath.Join(currentPath, ".update"), os.ModePerm)
	copyFile(filepath.Join(bkp, "backup.zip"), filepath.Join(currentPath, ".update", "nvm4w-backup.zip"))

	// Copy the new files to the current directory
	// copyFile(currentExe, fmt.Sprintf("%s.%s.bak", currentExe, version))
	copyDirContents(filepath.Join(tmp, "assets"), currentPath)
	copyFile(filepath.Join(tmp, "assets", "nvm.exe"), filepath.Join(currentPath, ".update/nvm.exe"))

	if verbose {
		nvmtestcmd := exec.Command(filepath.Join(currentPath, ".update/nvm.exe"), "version")
		nvmtestcmd.Stdout = os.Stdout
		nvmtestcmd.Stderr = os.Stderr
		err = nvmtestcmd.Run()
		if err != nil {
			status <- Status{Err: err}
		}

View on GitHub (pinned to 5b18223ca1)

Solutions

  1. Close all node processes and shells whose working directory is inside the nvm tree, then retry the upgrade.
  2. Run the upgrade from an elevated prompt so locked-but-readable system files can still be read.
  3. Temporarily disable real-time antivirus scanning for NVM_HOME.
  4. If it still fails, manually back up NVM_HOME, then delete and reinstall nvm-windows fresh.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure no node/nvm processes hold files in the install tree before upgrade
out, _ := exec.Command("tasklist", "/FI", "IMAGENAME eq node.exe").Output()
if !strings.Contains(string(out), "No tasks") {
    fmt.Println("stop node processes before upgrading")
}

Try / catch

Catch, report which phase failed (backup), and reassure that the old install is intact. Direct the user to close locking processes and retry.

Prevention

When it happens

Trigger: A node.exe managed by nvm is running (its files under the symlinked version dir are locked on Windows); nvm.exe itself running from the directory being zipped; antivirus holding an exclusive handle on recently written files; path longer than MAXPATH inside the install tree; NVM_HOME on a network share with read glitches.

Common situations: Upgrading while a dev server or node REPL is open; upgrading from a shell whose CWD is inside NVM_HOME; OneDrive/Defender scanning the install dir mid-zip.

Related errors


AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15). Data as JSON: /api/errors/dde3f21832a176c1. Report an issue: GitHub.