ERR_FS_CP_FIFO_PIPE
Node.jsERRORCriticalFilesystemHIGH confidence

Cannot copy a FIFO or pipe with fs.cp()

Production Risk

Low — primarily affects Unix/Linux environments with named pipes.

What this means

Thrown when fs.cp() encounters a FIFO (named pipe) as the source or encounters such a file type when copying recursively. FIFOs and pipes cannot be copied like regular files because they do not have static content.

Why it happens
  1. 1Copying a directory tree that contains FIFO/pipe files
  2. 2Explicitly specifying a named pipe as the source of cp()
How to reproduce

Triggered when cp() encounters a file with type FIFO during copy traversal.

trigger — this will error
trigger — this will error
const fs = require('fs');
// If src-dir contains a named pipe:
fs.cpSync('./src-dir', './dest-dir', { recursive: true }); // throws on the pipe

expected output

Error [ERR_FS_CP_FIFO_PIPE]: Cannot copy a FIFO pipe: '/src-dir/named-pipe'

Fix

Use the filter option to skip special files

WHEN When copying directory trees that may contain FIFOs

Use the filter option to skip special files
const fs = require('fs');
fs.cpSync('./src-dir', './dest-dir', {
  recursive: true,
  filter: (src) => {
    const stat = fs.statSync(src);
    return !stat.isFIFO(); // skip FIFO files
  },
});

Why this works

The filter callback lets you exclude file types that cp() cannot handle.

Code examples
Triggerjs
const fs = require('fs');
// If src-dir contains a named pipe:
fs.cpSync('./src-dir', './dest-dir', { recursive: true }); // throws on the pipe  // this triggers ERR_FS_CP_FIFO_PIPE
Handle in try/catchjs
try {
  // operation that may throw ERR_FS_CP_FIFO_PIPE
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_FS_CP_FIFO_PIPE') {
    console.error('ERR_FS_CP_FIFO_PIPE:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_fs_cp_fifo_pipe(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Use cp() to copy directories that may contain named pipes without a filter

FIFOs cannot be copied; the operation will fail unless filtered out.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors