{"record":{"id":"83dc7799c53058b8","repo":"parcel-bundler/parcel","slug":"targets-option-is-an-empty-array","errorCode":null,"errorMessage":"Targets option is an empty array","messagePattern":"Targets option is an empty array","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/requests/TargetRequest.js","lineNumber":215,"sourceCode":"    this.targetInfo = new Map();\n  }\n\n  async resolve(\n    rootDir: FilePath,\n    exclusiveTarget?: string,\n  ): Promise<Array<Target>> {\n    let optionTargets = this.options.targets;\n    if (exclusiveTarget != null && optionTargets == null) {\n      optionTargets = [exclusiveTarget];\n    }\n\n    let packageTargets: Map<string, Target | null> =\n      await this.resolvePackageTargets(rootDir, exclusiveTarget);\n    let targets: Array<Target>;\n    if (optionTargets) {\n      if (Array.isArray(optionTargets)) {\n        if (optionTargets.length === 0) {\n          throw new ThrowableDiagnostic({\n            diagnostic: {\n              message: `Targets option is an empty array`,\n              origin: '@parcel/core',\n            },\n          });\n        }\n\n        // Only build the intersection of the exclusive target and option targets.\n        if (exclusiveTarget != null) {\n          optionTargets = optionTargets.filter(\n            target => target === exclusiveTarget,\n          );\n        }\n\n        // If an array of strings is passed, it's a filter on the resolved package\n        // targets. Load them, and find the matching targets.\n        targets = optionTargets\n          .map(target => {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/requests/TargetRequest.js#L197-L233","documentation":"Thrown by TargetRequest.resolve() when this.options.targets is an empty array []. Passing an empty targets array is explicitly invalid — it would produce zero build targets. Parcel catches this early with a clear message rather than silently building nothing.","triggerScenarios":"At the top of resolve(), after optionTargets = this.options.targets. If optionTargets is truthy, Array.isArray(optionTargets) is true, and optionTargets.length === 0, the error fires before any target resolution.","commonSituations":"Programmatically constructing Parcel options and passing targets: [] by mistake (e.g., from a filtered array that ended up empty); CLI flag --target passed with no values producing an empty array; configuration computed at runtime that resolves to empty.","solutions":["If you want all targets, pass targets: undefined or omit the option entirely.","If filtering targets programmatically, guard against the empty result and either omit the option or throw your own clearer error.","Ensure at least one target name is present when passing an array."],"exampleFix":"// before\nconst bundler = new Parcel({\n  entries: 'src/index.html',\n  targets: activeTargets, // activeTargets happens to be []\n});\n\n// after\nconst bundler = new Parcel({\n  entries: 'src/index.html',\n  targets: activeTargets.length > 0 ? activeTargets : undefined,\n});","handlingStrategy":"validation","validationCode":"function validateTargetsOption(targets) {\n  if (Array.isArray(targets) && targets.length === 0) {\n    throw new Error('targets option cannot be an empty array; pass undefined to use all targets.');\n  }\n}","typeGuard":"function isValidTargetsOption(targets) {\n  return targets == null\n    || (Array.isArray(targets) && targets.length > 0)\n    || (typeof targets === 'object' && !Array.isArray(targets));\n}","tryCatchPattern":null,"preventionTips":["When filtering targets programmatically, default to undefined if the filter yields an empty array.","Validate the targets option shape before passing it to the Parcel constructor.","In CLI scripts, check that --target values resolve to at least one target."],"tags":["targets","config","validation","api-usage"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}