BabylonJS/Babylon.js · error · Error

Service '${contract.toString()}' has not been registered in

Error message

Service '${contract.toString()}' has not been registered in the '${this._friendlyName}' container.

What it means

_resolveDependency walked the local container's _serviceDefinitions, then the full parent chain via this._parent._resolveDependency, and found no registration at all for the requested contract. This is the terminal 'unknown contract' error, distinct from error 831 which fires when the contract is registered but not instantiated.

Source

Thrown at packages/dev/sharedUiComponents/src/modularTool/modularity/serviceContainer.ts:148

            const instance = this._serviceInstances.get(definition);
            if (!instance) {
                throw new Error(`Service '${contract.toString()}' has not been instantiated in the '${this._friendlyName}' container.`);
            }

            let dependentDefinitions = this._serviceDependents.get(definition);
            if (!dependentDefinitions) {
                this._serviceDependents.set(definition, (dependentDefinitions = new Set()));
            }
            dependentDefinitions.add(consumer);

            return instance;
        }

        if (this._parent) {
            return this._parent._resolveDependency(contract, consumer);
        }

        throw new Error(`Service '${contract.toString()}' has not been registered in the '${this._friendlyName}' container.`);
    }

    /**
     * Removes a consumer from the dependent set for a given contract, checking locally first then the parent chain.
     * @param contract The contract identity.
     * @param consumer The service definition to remove as a dependent.
     */
    private _removeDependentFromChain(contract: symbol, consumer: WeaklyTypedServiceDefinition): void {
        const definition = this._serviceDefinitions.get(contract);
        if (definition) {
            const dependentDefinitions = this._serviceDependents.get(definition);
            if (dependentDefinitions) {
                dependentDefinitions.delete(consumer);
                if (dependentDefinitions.size === 0) {
                    this._serviceDependents.delete(definition);
                }
            }
            return;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Add the service definition that produces the missing contract to the container (or its parent).
  2. Import contract symbols from the single shared module that owns them; never create inline Symbol() contracts.
  3. Check the container hierarchy: register the producer in a parent container if it must serve children.
  4. Verify module load order so the producer is registered before consumers resolve dependencies.

Example fix

// before
const FooContract = Symbol("Foo"); // local symbol, not the registered one
// after
import { FooContract } from "./contracts"; // shared symbol identity
Defensive patterns

Strategy: type-guard

Validate before calling

// const contracts = new Set(loadedListedContracts);
// if (!def.consumes.every((c) => contracts.has(c))) throw new Error("missing producer module");

Type guard

function isRegistered(contract) {
  return typeof contract === "symbol" && knownContracts.has(contract);
}

Try / catch

// try {
//   return container.dependencies(def);
// } catch (e) {
//   if (String(e.message).includes("has not been registered")) {
//     throw new Error(`Producer for ${e.message.match(/'(.*)'/)?.[1]} missing — did you load its module?`, { cause: e });
//   }
//   throw e;
// }

Prevention

When it happens

Trigger: Calling container.dependencies(definition) where definition.consumes contains a contract never registered (via produces) in this container or any ancestor; typo/mismatch of contract symbols; module providing the service not loaded.

Common situations: Forgetting to add the module/service that produces the dependency; using two different symbol instances for what the developer thinks is one contract (e.g. each file calling Symbol('foo') instead of importing a shared symbol); resolving a service in a child container whose parent chain doesn't host the producer.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/defc2cbef750e62f. Report an issue: GitHub.