{"record":{"id":"3406103d419376f7","repo":"vercel/next.js","slug":"src-and-dest-are-required","errorCode":null,"errorMessage":"`src` and `dest` are required","messagePattern":"`src` and `dest` are required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/create-next-app/helpers/copy.ts","lineNumber":22,"sourceCode":"import { async as glob } from 'fast-glob'\n\ninterface CopyOption {\n  cwd?: string\n  rename?: (basename: string) => string\n  parents?: boolean\n}\n\nconst identity = (x: string) => x\n\nexport const copy = async (\n  src: string | string[],\n  dest: string,\n  { cwd, rename = identity, parents = true }: CopyOption = {}\n) => {\n  const source = typeof src === 'string' ? [src] : src\n\n  if (source.length === 0 || !dest) {\n    throw new TypeError('`src` and `dest` are required')\n  }\n\n  const sourceFiles = await glob(source, {\n    cwd,\n    dot: true,\n    absolute: false,\n    stats: false,\n  })\n\n  const destRelativeToCwd = cwd ? resolve(cwd, dest) : dest\n\n  return Promise.all(\n    sourceFiles.map(async (p) => {\n      const dirName = dirname(p)\n      const baseName = rename(basename(p))\n\n      const from = cwd ? resolve(cwd, p) : p\n      const to = parents","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/create-next-app/helpers/copy.ts#L4-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the caller passes a non-empty `src` (string or string[]) and a non-empty `dest` string.","If the source list is dynamic, guard upstream: skip the copy or error with a clearer message when it is empty.","Check the template helper that computes src/dest for undefined values caused by missing CLI options.","Add a unit test calling `copy` with realistic inputs to catch regressions."],"exampleFix":"// before\ncopy([], 'app')\ncopy(src, undefinedDest)\n\n// after\ncopy(['template/**'], 'app')\ncopy(src, dest ?? 'app')","handlingStrategy":"validation","validationCode":"import { copy } from './copy'\nconst src = ['template/**/*']\nconst dest = process.env.OUT_DIR\nif (src.length === 0 || !dest) throw new Error('Caller bug: empty src or missing dest')\nawait copy(src, dest)","typeGuard":"function areCopyArgs(src: unknown, dest: unknown): src is string[] | string {\n  return ((Array.isArray(src) && src.length > 0) || (typeof src === 'string' && src.length > 0))\n    && typeof dest === 'string' && dest.length > 0\n}","tryCatchPattern":null,"preventionTips":["Always check src is non-empty and dest is a non-empty string before calling copy().","Log computed src/dest when they come from CLI flags.","Add unit tests for copy() happy and error paths."],"tags":["create-next-app","internal-api","validation","filesystem"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}