{"record":{"id":"7bbdf66e98105f51","repo":"parcel-bundler/parcel","slug":"invalid-distpath-for-target-targetname","errorCode":null,"errorMessage":"Invalid distPath for target \"${targetName}\"","messagePattern":"Invalid distPath for target \"(.+?)\"","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/requests/TargetRequest.js","lineNumber":1009,"sourceCode":"          distDir = path.join(distDir, targetName);\n        }\n        invariant(pkgMap != null);\n        invariant(typeof pkgFilePath === 'string');\n        loc = {\n          filePath: pkgFilePath,\n          ...getJSONSourceLocation(\n            pkgMap.pointers[`/targets/${targetName}`],\n            'key',\n          ),\n        };\n      } else {\n        if (typeof distPath !== 'string') {\n          let contents: string =\n            typeof pkgContents === 'string'\n              ? pkgContents\n              : // $FlowFixMe\n                JSON.stringify(pkgContents, null, '\\t');\n          throw new ThrowableDiagnostic({\n            diagnostic: {\n              message: md`Invalid distPath for target \"${targetName}\"`,\n              origin: '@parcel/core',\n              codeFrames: [\n                {\n                  language: 'json',\n                  filePath: pkgFilePath ?? undefined,\n                  code: contents,\n                  codeHighlights: generateJSONCodeHighlights(contents, [\n                    {\n                      key: `/${targetName}`,\n                      type: 'value',\n                      message: 'Expected type string',\n                    },\n                  ]),\n                },\n              ],\n            },","sourceCodeStart":991,"sourceCodeEnd":1027,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/requests/TargetRequest.js#L991-L1027","documentation":"Each target needs a string `distDir` (output directory). When the resolved `distPath` is present but not a string (e.g. a number, object, or array was provided for the target field), TargetRequest throws `Invalid distPath for target \"<name>\"`. The highlight points at `/<targetName>` in package.json.","triggerScenarios":"Providing a non-string value for a target's dist path in package.json, e.g. `\"main\": 123` or `\"main\": [\"a.js\",\"b.js\"]` in a context where a single string path is required.","commonSituations":"JSON typo where a target field is set to a number/array/object; tooling that auto-generates package.json with malformed target values; mixing the legacy `main: string` API with the `targets` object form incorrectly.","solutions":["Set the target field to a string output file path, e.g. `\"main\": \"dist/index.js\"`.","If using the `targets` object form, ensure each target's `distDir`/`source` values are strings.","Validate package.json with a JSON schema linter for Parcel target fields."],"exampleFix":"// before (package.json)\n{\n  \"main\": [\"dist/index.js\"]\n}\n\n// after\n{\n  \"main\": \"dist/index.js\"\n}","handlingStrategy":"type-guard","validationCode":"function assertTargetDistPath(pkg) {\n  for (const [name, value] of Object.entries(pkg.targets || {})) {\n    if (value?.distDir != null && typeof value.distDir !== 'string') {\n      throw new Error(`targets.${name}.distDir must be a string`);\n    }\n  }\n  for (const f of ['main','module','browser','types']) {\n    if (f in pkg && typeof pkg[f] !== 'string') {\n      throw new Error(`Field ${f} must be a string path`);\n    }\n  }\n}","typeGuard":"function isStringDistPath(v) {\n  return v == null || typeof v === 'string';\n}","tryCatchPattern":"try { await parcel.run(); } catch (e) {\n  if (/Invalid distPath for target/.test(e.message)) {\n    console.error('Ensure target dist path fields are strings.');\n  } else throw e;\n}","preventionTips":["Always use string paths for target output fields.","Lint package.json against the Parcel target JSON schema.","Avoid arrays/objects for single-output target fields."],"tags":["parcel","targets","dist-path","type-mismatch","config"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}