Cannot copy a FIFO or pipe with fs.cp()
Production Risk
Low — primarily affects Unix/Linux environments with named pipes.
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.
- 1Copying a directory tree that contains FIFO/pipe files
- 2Explicitly specifying a named pipe as the source of cp()
Triggered when cp() encounters a file with type FIFO during copy traversal.
const fs = require('fs');
// If src-dir contains a named pipe:
fs.cpSync('./src-dir', './dest-dir', { recursive: true }); // throws on the pipeexpected 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
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.
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_PIPEtry {
// 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
}
}// Validate inputs before calling the operation
function safe_err_fs_cp_fifo_pipe(...args) {
// validate args here
return performOperation(...args)
}✕ Use cp() to copy directories that may contain named pipes without a filter
FIFOs cannot be copied; the operation will fail unless filtered out.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev