vercel/next.js · error · TypeError

`src` and `dest` are required

Error message

`src` and `dest` are required

What it means

create-next-app's `copy()` helper throws a TypeError when the `src` array is empty OR the `dest` string is falsy — both are required to perform a copy. This is an internal API used by CNA templates, so the error signals a programming bug in a caller (template generator) rather than user input.

Source

Thrown at packages/create-next-app/helpers/copy.ts:22

import { async as glob } from 'fast-glob'

interface CopyOption {
  cwd?: string
  rename?: (basename: string) => string
  parents?: boolean
}

const identity = (x: string) => x

export const copy = async (
  src: string | string[],
  dest: string,
  { cwd, rename = identity, parents = true }: CopyOption = {}
) => {
  const source = typeof src === 'string' ? [src] : src

  if (source.length === 0 || !dest) {
    throw new TypeError('`src` and `dest` are required')
  }

  const sourceFiles = await glob(source, {
    cwd,
    dot: true,
    absolute: false,
    stats: false,
  })

  const destRelativeToCwd = cwd ? resolve(cwd, dest) : dest

  return Promise.all(
    sourceFiles.map(async (p) => {
      const dirName = dirname(p)
      const baseName = rename(basename(p))

      const from = cwd ? resolve(cwd, p) : p
      const to = parents

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Ensure the caller passes a non-empty `src` (string or string[]) and a non-empty `dest` string.
  2. If the source list is dynamic, guard upstream: skip the copy or error with a clearer message when it is empty.
  3. Check the template helper that computes src/dest for undefined values caused by missing CLI options.
  4. Add a unit test calling `copy` with realistic inputs to catch regressions.

Example fix

// before
copy([], 'app')
copy(src, undefinedDest)

// after
copy(['template/**'], 'app')
copy(src, dest ?? 'app')
Defensive patterns

Strategy: validation

Validate before calling

import { copy } from './copy'
const src = ['template/**/*']
const dest = process.env.OUT_DIR
if (src.length === 0 || !dest) throw new Error('Caller bug: empty src or missing dest')
await copy(src, dest)

Type guard

function areCopyArgs(src: unknown, dest: unknown): src is string[] | string {
  return ((Array.isArray(src) && src.length > 0) || (typeof src === 'string' && src.length > 0))
    && typeof dest === 'string' && dest.length > 0
}

Prevention

When it happens

Trigger: Calling `copy()` with an empty array `copy([], dest)`, with `copy(src, '')`, or `copy(src, undefined)`; typically inside a CNA template helper that computed the source list dynamically and got an empty result, or that read a missing dest path.

Common situations: A custom create-next-app template whose glob returned no files; passing a config-derived dest that was undefined because the flag wasn't supplied; refactoring a template and dropping an argument.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/3406103d419376f7. Report an issue: GitHub.