{"record":{"id":"436bd71322329b9f","repo":"parcel-bundler/parcel","slug":"declared-output-format-descriptor-outputformat","errorCode":null,"errorMessage":"Declared output format \"${descriptor.outputFormat}\" does not match expected output format \"${inferredOutputFormat}\".","messagePattern":"Declared output format \"(.+?)\" does not match expected output format \"(.+?)\"\\.","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/requests/TargetRequest.js","lineNumber":1280,"sourceCode":"        typeof pkgContents === 'string'\n          ? pkgContents\n          : // $FlowFixMe\n            JSON.stringify(pkgContents, null, '\\t');\n      let expectedExtensions;\n      switch (descriptor.outputFormat) {\n        case 'esmodule':\n          expectedExtensions = ['.mjs', '.js'];\n          break;\n        case 'commonjs':\n          expectedExtensions = ['.cjs', '.js'];\n          break;\n        case 'global':\n          expectedExtensions = ['.js'];\n          break;\n      }\n      // $FlowFixMe\n      let listFormat = new Intl.ListFormat('en-US', {type: 'disjunction'});\n      throw new ThrowableDiagnostic({\n        diagnostic: {\n          message: md`Declared output format \"${descriptor.outputFormat}\" does not match expected output format \"${inferredOutputFormat}\".`,\n          origin: '@parcel/core',\n          codeFrames: [\n            {\n              language: 'json',\n              filePath: pkgFilePath ?? undefined,\n              code: contents,\n              codeHighlights: generateJSONCodeHighlights(contents, [\n                {\n                  key: `/targets/${targetName}/outputFormat`,\n                  type: 'value',\n                  message: 'Declared output format defined here',\n                },\n                {\n                  key: nullthrows(inferredOutputFormatField),\n                  type: 'value',\n                  message: 'Inferred output format defined here',","sourceCodeStart":1262,"sourceCodeEnd":1298,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/requests/TargetRequest.js#L1262-L1298","documentation":"Parcel infers the correct outputFormat from the distEntry extension and package.json `type` field. If you explicitly set `descriptor.outputFormat` and it disagrees with the inferred format, the build aborts. The expected extensions per format are listed (.mjs/.js for esmodule, .cjs/.js for commonjs, .js for global).","triggerScenarios":"Setting `targets.<name>.outputFormat` to a value that conflicts with the extension/type-derived format for that target's distEntry.","commonSituations":"Hardcoding outputFormat while changing extensions; package.json `\"type\": \"module\"` interacting with a `commonjs` outputFormat setting; partial config migrations where format and extension drift apart.","solutions":["Align the explicit outputFormat with the extension (e.g. esmodule + .mjs, commonjs + .cjs).","Remove the explicit outputFormat and let Parcel infer it from the extension/type.","Adjust the extension or `\"type\"` field to match the desired format."],"exampleFix":"// before (package.json)\n{\n  \"main\": \"dist/index.cjs\",\n  \"targets\": { \"main\": { \"outputFormat\": \"esmodule\" } }\n}\n\n// after\n{\n  \"main\": \"dist/index.mjs\",\n  \"targets\": { \"main\": { \"outputFormat\": \"esmodule\" } }\n}","handlingStrategy":"validation","validationCode":"function inferFormat(entry, pkgType) {\n  if (entry.endsWith('.mjs')) return 'esmodule';\n  if (entry.endsWith('.cjs')) return 'commonjs';\n  return pkgType === 'module' ? 'esmodule' : 'commonjs';\n}\nfunction assertFormatMatches(targets, pkg) {\n  for (const [name, d] of Object.entries(targets || {})) {\n    if (!d.outputFormat) continue;\n    const inferred = inferFormat(d.distEntry || pkg[name], pkg.type);\n    if (d.outputFormat !== inferred) {\n      throw new Error(`Target ${name}: outputFormat ${d.outputFormat} != inferred ${inferred}`);\n    }\n  }\n}","typeGuard":"function outputFormatCoherent(d, inferred) {\n  return d.outputFormat == null || d.outputFormat === inferred;\n}","tryCatchPattern":"try { await parcel.run(); } catch (e) {\n  if (/does not match expected output format/.test(e.message)) {\n    console.error('Align explicit outputFormat with extension/package type.');\n  } else throw e;\n}","preventionTips":["Omit outputFormat and let Parcel infer from extension/type.","When setting outputFormat, change the extension to match.","Document the extension↔format mapping in shared config."],"tags":["parcel","targets","output-format","extensions","config"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}