parcel-bundler/parcel · error · Error

Dependency not found

Error message

Dependency not found

What it means

`MutableBundleGraph.createBundleGroup(dependency, target)` looks up the dependency by its content key in the internal graph. If no node with that id exists, the dependency was never added (or has been removed) and creating a bundle group around it is impossible. The same method separately checks that the dependency resolves to an asset.

Source

Thrown at packages/core/core/src/public/MutableBundleGraph.js:86

  addEntryToBundle(
    asset: IAsset,
    bundle: IBundle,
    shouldSkipDependency?: IDependency => boolean,
  ) {
    this.#graph.addEntryToBundle(
      assetToAssetValue(asset),
      bundleToInternalBundle(bundle),
      shouldSkipDependency
        ? d => shouldSkipDependency(new Dependency(d, this.#options))
        : undefined,
    );
  }

  createBundleGroup(dependency: IDependency, target: Target): IBundleGroup {
    let dependencyNode = this.#graph._graph.getNodeByContentKey(dependency.id);
    if (!dependencyNode) {
      throw new Error('Dependency not found');
    }

    invariant(dependencyNode.type === 'dependency');

    let resolved = this.#graph.getResolvedAsset(
      dependencyToInternalDependency(dependency),
    );
    if (!resolved) {
      throw new Error(
        'Dependency did not resolve to an asset ' + dependency.id,
      );
    }

    let bundleGroup: InternalBundleGroup = {
      target: targetToInternalTarget(target),
      entryAssetId: resolved.id,
    };

View on GitHub (pinned to 59484858a1)

Solutions

  1. Obtain the dependency from `asset.addDependency(...)` or the graph's own APIs rather than caching it.
  2. Before calling `createBundleGroup`, verify the dependency is still in the graph.
  3. Re-resolve dependencies after any graph mutation that may have removed nodes.

Example fix

// before
const dep = cachedDependency; // may be stale
graph.createBundleGroup(dep, target);

// after
const dep = graph.getDependencies(asset)[0];
if (dep) graph.createBundleGroup(dep, target);
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the dependency exists in the graph before grouping.
const node = graph._graph.getNodeByContentKey(dependency.id);
if (!node) throw new Error(`dependency ${dependency.id} not in graph`);
graph.createBundleGroup(dependency, target);

Type guard

function dependencyInGraph(graph: any, id: string): boolean {
  return graph._graph.getNodeByContentKey(id) != null;
}

Prevention

When it happens

Trigger: A custom packager calls `createBundleGroup(dep, target)` with a dependency object whose `id` is not present in the bundle graph (e.g. from a stale reference, a different graph, or before `addDependency`).

Common situations: Holding onto a dependency reference across graph rebuilds; constructing a Dependency manually rather than obtaining it from `addDependency`.

Related errors


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