{"record":{"id":"1965018340069fa0","repo":"parcel-bundler/parcel","slug":"missing-distdir-for-target-name","errorCode":null,"errorMessage":"Missing distDir for target \"${name}\"","messagePattern":"Missing distDir for target \"(.+?)\"","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/requests/TargetRequest.js","lineNumber":263,"sourceCode":"          .filter(Boolean);\n      } else {\n        // Otherwise, it's an object map of target descriptors (similar to those\n        // in package.json). Adapt them to native targets.\n        targets = Object.entries(optionTargets)\n          .map(([name, _descriptor]) => {\n            let {distDir, ...descriptor} = parseDescriptor(\n              name,\n              _descriptor,\n              null,\n              JSON.stringify({targets: optionTargets}, null, '\\t'),\n            );\n            if (distDir == null) {\n              let optionTargetsString = JSON.stringify(\n                optionTargets,\n                null,\n                '\\t',\n              );\n              throw new ThrowableDiagnostic({\n                diagnostic: {\n                  message: md`Missing distDir for target \"${name}\"`,\n                  origin: '@parcel/core',\n                  codeFrames: [\n                    {\n                      code: optionTargetsString,\n                      codeHighlights: generateJSONCodeHighlights(\n                        optionTargetsString || '',\n                        [\n                          {\n                            key: `/${name}`,\n                            type: 'value',\n                          },\n                        ],\n                      ),\n                    },\n                  ],\n                },","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/requests/TargetRequest.js#L245-L281","documentation":"Thrown by TargetRequest.resolve() when targets are passed as an object map (not an array) and a target descriptor is missing the required distDir property. distDir specifies the output directory for that target and is mandatory for object-form targets. A code frame highlights the offending target in the serialized options.","triggerScenarios":"In the Object.entries(optionTargets).map() branch, parseDescriptor extracts distDir from the descriptor. If distDir == null (absent or explicitly null), the error fires with a JSON code frame showing the target's value in the option targets string.","commonSituations":"Passing targets as an object programmatically and forgetting distDir; copy-pasting a target descriptor from package.json (which can infer distDir) into the API (which cannot); assuming distDir defaults to 'dist' — it does not for object-form targets.","solutions":["Add a distDir property to the target descriptor in the options object.","If you want the default output directory, set distDir to 'dist' explicitly.","Verify every target in the object map has distDir — the code frame shows which one is missing.","Consider using package.json targets instead, where distDir can be inferred from the target name."],"exampleFix":"// before\nconst bundler = new Parcel({\n  entries: 'src/index.html',\n  targets: {\n    app: {\n      context: 'browser',\n      outputFormat: 'esmodule'\n      // distDir missing\n    }\n  }\n});\n\n// after\nconst bundler = new Parcel({\n  entries: 'src/index.html',\n  targets: {\n    app: {\n      distDir: 'dist',\n      context: 'browser',\n      outputFormat: 'esmodule'\n    }\n  }\n});","handlingStrategy":"validation","validationCode":"function validateObjectTargetsHaveDistDir(targets) {\n  if (targets == null || Array.isArray(targets)) return;\n  for (const [name, descriptor] of Object.entries(targets)) {\n    if (descriptor.distDir == null) {\n      throw new Error(`Target \"${name}\" is missing required \"distDir\" property.`);\n    }\n  }\n}","typeGuard":"function hasAllDistDirs(targets) {\n  if (targets == null || Array.isArray(targets)) return true;\n  return Object.entries(targets).every(([, d]) => d != null && typeof d.distDir === 'string' && d.distDir.length > 0);\n}","tryCatchPattern":null,"preventionTips":["When passing targets as an object, always include distDir for each entry.","Prefer package.json targets where distDir can be inferred from the target name.","Validate the targets object shape before constructing the Parcel instance."],"tags":["targets","config","distdir","validation","api-usage"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}