parcel-bundler/parcel · error · ThrowableDiagnostic

Target "${target.name}" is configured to overwrite entry "${

Error message

Target "${target.name}" is configured to overwrite entry "${relativeEntry}".

What it means

Each target's output destination must not equal a source entry file path. If a target's distPath resolves to the same file as an input entry, the build would overwrite the source. TargetRequest throws with the relative entry path and a hint clarifying that target fields like `main`/`module` are OUTPUT paths. For common targets the hint reminds the user these are output fields.

Source

Thrown at packages/core/core/src/requests/TargetRequest.js:1521

        let inputLoc = input.loc;
        if (inputLoc) {
          let highlight = convertSourceLocationToHighlight(
            inputLoc,
            'Entry defined here',
          );

          if (inputLoc.filePath === loc.filePath) {
            codeFrames[0].codeHighlights.push(highlight);
          } else {
            codeFrames.push({
              filePath: fromProjectPath(options.projectRoot, inputLoc.filePath),
              codeHighlights: [highlight],
            });
          }
        }
      }

      throw new ThrowableDiagnostic({
        diagnostic: {
          origin: '@parcel/core',
          message: `Target "${target.name}" is configured to overwrite entry "${relativeEntry}".`,
          codeFrames,
          hints: [
            (COMMON_TARGETS[target.name]
              ? `The "${target.name}" field is an _output_ file path so that your build can be consumed by other tools. `
              : '') +
              `Change the "${target.name}" field to point to an output file rather than your source code.`,
          ],
          documentationURL: 'https://parceljs.org/features/targets/',
        },
      });
    }
  }
}

async function debugResolvedTargets(input, targets, targetInfo, options) {

View on GitHub (pinned to 59484858a1)

Solutions

  1. Change the target field to point at an output location (e.g. `dist/index.js`), not the source.
  2. Move the entry file or output directory so they do not collide.
  3. Set an explicit `source` field distinct from the target output path.

Example fix

// before (package.json)
{
  "source": "src/index.js",
  "main": "src/index.js"
}

// after
{
  "source": "src/index.js",
  "main": "dist/index.js"
}
Defensive patterns

Strategy: validation

Validate before calling

import path from 'path';
function assertNoEntryOverlap(pkg) {
  const entries = [pkg.source, ...(pkg.entries || [])].filter(Boolean);
  const outs = ['main','module','browser','types'].map(f => pkg[f]).filter(Boolean);
  for (const o of outs) {
    if (entries.some(e => path.resolve(e) === path.resolve(o))) {
      throw new Error(`Target output ${o} collides with a source entry.`);
    }
  }
}

Type guard

function outputDoesNotOverlapEntries(outputPath, entries) {
  return !entries.some(e => path.resolve(e) === path.resolve(outputPath));
}

Try / catch

try { await parcel.run(); } catch (e) {
  if (/configured to overwrite entry/.test(e.message)) {
    console.error('Target output path must differ from source entry paths.');
  } else throw e;
}

Prevention

When it happens

Trigger: Pointing a target output field (e.g. `main`, `module`, or a custom target) at the same path as a source/entry file (e.g. `"main": "src/index.js"` while `src/index.js` is the entry).

Common situations: Confusing input `source` and output `main`/`module` fields; pointing `main` at a src file by mistake; refactoring that moved entry files into a location equal to an output path.

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/83734cece35e8266. Report an issue: GitHub.