denoland/deno · error · NodeSystemError
ERR_FS_CP_EEXIST
ERR_FS_CP_EEXIST
Error message
Target already exists
What it means
ERR_FS_CP_EEXIST ('Target already exists') is raised by throwCpError for kind 'EEXIST': the destination exists and the options forbid overwriting it — i.e. force: false combined with errorOnExist: true (the native on-file/link ops receive opts.force and opts.errorOnExist). With defaults (force: true, errorOnExist: false) existing destinations are overwritten silently.
Source
Thrown at ext/node/polyfills/_fs/cp/cp.ts:84
});
case "DIR_TO_NON_DIR":
throw new ERR_FS_CP_DIR_TO_NON_DIR({
message: err.message,
path: err.path,
syscall: "cp",
errno: EISDIR,
code: "EISDIR",
});
case "NON_DIR_TO_DIR":
throw new ERR_FS_CP_NON_DIR_TO_DIR({
message: err.message,
path: err.path,
syscall: "cp",
errno: ENOTDIR,
code: "ENOTDIR",
});
case "EEXIST":
throw new ERR_FS_CP_EEXIST({
message: err.message,
path: err.path,
syscall: "cp",
errno: EEXIST,
code: "EEXIST",
});
case "EISDIR":
throw new ERR_FS_EISDIR({
message: err.message,
path: err.path,
syscall: "cp",
errno: EISDIR,
code: "EISDIR",
});
case "SOCKET":
throw new ERR_FS_CP_SOCKET({
message: err.message,
path: err.path,View on GitHub (pinned to 89f33cbef2)
Solutions
- If overwriting is fine, drop errorOnExist or set force: true
- If not overwriting is intended, catch the error and check err.code === 'ERR_FS_CP_EEXIST' (or EEXIST) to treat it as success
- Pre-check with fs.existsSync(dest) / fsp.lstat to branch explicitly instead of relying on the throw
Example fix
// before
await fsp.cp(src, dest, { force: false, errorOnExist: true }); // throws when dest exists
// after
try {
await fsp.cp(src, dest, { force: false, errorOnExist: true });
} catch (err) {
if (err.code !== 'EEXIST' && err.code !== 'ERR_FS_CP_EEXIST') throw err;
// dest already present — treat as done
} Defensive patterns
Strategy: try-catch
Validate before calling
if (await fsp.lstat(dest).catch(() => null)) {
// dest exists: overwrite (default), or skip, or abort — decide explicitly
if (!overwrite) return;
} Try / catch
try {
await fsp.cp(src, dest, { force: false, errorOnExist: true });
} catch (err) {
if (err.code !== 'EEXIST' && err.code !== 'ERR_FS_CP_EEXIST') throw err;
console.log('dest already exists — skipping');
} Prevention
- Know the option matrix: force:true overwrites, errorOnExist:true turns existence into an error
- Use existence pre-checks when 'already installed' should be a normal case
- Check err.code, never the message text, when branching on fs errors
When it happens
Trigger: await fsp.cp(src, dest, { force: false, errorOnExist: true }) when dest already exists; install/extract tools that intentionally refuse to clobber outputs.
Common situations: Idempotent deploy scripts that must not overwrite existing installs; cache-population code where EEXIST is used as 'already done'.
Related errors
- ERR_FS_CP_EINVAL
- ERR_FS_CP_DIR_TO_NON_DIR
- ERR_FS_CP_NON_DIR_TO_DIR
- A file exists at the destination: ${destStr}
- ERR_FS_EISDIR
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/4b9114d3985fa25a.
Report an issue: GitHub.