sinelaw/fresh · warning

Could not delete archive file:

Error message

Could not delete archive file:

What it means

In the npm package's binary-install.js install() function, after extraction the code tries to unlink the downloaded archive; if fs.unlinkSync throws (and the file still exists), it logs 'Could not delete archive file:' via console.warn. It is a non-fatal cleanup warning — installation proceeds to verify the binary — but indicates a filesystem problem with the temp archive.

Solutions

  1. Treat as a warning: verify the binary actually installed; delete the leftover archive manually.
  2. Check permissions on the directory holding archivePath and ensure the install runs as a user with write access.
  3. Exclude the npm cache/temp directory from antivirus real-time scanning (common on Windows).
  4. Re-run npm install after closing processes that may lock the file.
Defensive patterns

Strategy: try-catch

Validate before calling

if (fs.existsSync(archivePath) && (fs.statSync(archivePath).mode & 0o200) === 0) {
  fs.chmodSync(archivePath, 0o644);
}

Try / catch

try { install(); } catch (e) { if (String(e.message).includes('Could not delete archive')) { fs.rmSync(archivePath, { force: true }); install(); } else throw e; }

Prevention

When it happens

Trigger: fs.existsSync(archivePath) is true but unlinkSync fails: file locked by another process (Windows AV scanners), read-only filesystem, or permission mismatch on the temp/archive path.

Common situations: npm postinstall running on Windows while antivirus holds the freshly downloaded archive open; installing into a read-only mounted volume or globally without write permission to the archive location; disk-full conditions.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/c4f4e8abfe92d949. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor/npm-package/binary-install.js:145

                            fs.renameSync(srcPath, destPath);
                        }
                        fs.rmdirSync(nested);
                    }
                }
            }
        });
    } catch (error) {
        error.message = `Extraction failed after retries: ${error.message}. Archive: ${archivePath}`;
        throw error;
    }

    // Cleanup archive file
    try {
        if (fs.existsSync(archivePath)) {
            fs.unlinkSync(archivePath);
        }
    } catch (e) {
        console.warn('Could not delete archive file:', e.message);
    }

    // Verify binary exists
    if (!fs.existsSync(binaryPath)) {
        throw new Error(`Installation failed: binary not found at ${binaryPath}. Please check the release assets.`);
    }

    // Provenance receipt (sidecar next to the binary). Overrides the generic
    // `tarball` receipt that ships inside the archive so the editor defers
    // updates to npm rather than self-swapping.
    try {
        const receipt = [
            'schema = 1',
            'channel = "npm"',
            `version = "${VERSION}"`,
            'package_name = "fresh-editor"',
            'managed = true',
            'self_update = false',

View on GitHub (pinned to 67894ca546)