AUR0155

Warning Message

AUR0155: Value converter <converter-name> has already been registered.

Where <converter-name> is the name of the value converter that was attempted to be registered again.

Description

This warning indicates that an attempt was made to register a value converter with a specific name (e.g., dateFormat), but another value converter with the same name was already registered in the same scope (either globally or within the same component's dependencies). Aurelia requires value converter names to be unique within their registration scope.

Note: This is typically logged as a warning. The application may proceed, but only the first registration for the given name will be used, which could lead to incorrect data transformations if the duplicate registrations have different logic.

Cause

  1. Duplicate Global Registration: Calling Aurelia.register() multiple times with the same value converter class or different classes using the same converter name via the @valueConverter decorator.

  2. Duplicate Local Registration: Including the same value converter class multiple times in a component's dependencies array, or including different converter classes that resolve to the same converter name.

  3. Global and Local Conflict: Registering a converter globally and then attempting to register another converter with the same name locally within a component (or vice-versa).

  4. Naming Collision: Accidentally defining two different value converter classes that use the same converter name in their @valueConverter decorator.

Solution

  1. Ensure Unique Names: Choose a unique name for each value converter within its intended scope.

  2. Register Once: Ensure each value converter is registered only once per scope. Check global registrations (main.ts) and local dependencies arrays.

  3. Consolidate Registrations: Register globally if widely used, or locally if specific to few components. Avoid mixing registration types for the same name.

  4. Refactor/Rename: If two distinct converters share a name, rename one.

Example

// date-format.ts
import { valueConverter } from 'aurelia';
@valueConverter('dateFormat')
export class DateFormatValueConverter { /* ... */ }

// short-date-format.ts - Incorrect: Uses the same name
import { valueConverter } from 'aurelia';
@valueConverter('dateFormat') // Causes AUR0155 if both are registered
export class ShortDateFormatValueConverter { /* ... */ }

// --- main.ts ---
import { Aurelia } from 'aurelia';
import { DateFormatValueConverter } from './date-format';
import { ShortDateFormatValueConverter } from './short-date-format';

// Incorrect: Attempting to register two converters with the same name globally
// Aurelia.register(DateFormatValueConverter, ShortDateFormatValueConverter) /* ... */;

// Correct: Register only one implementation for the name 'dateFormat'
Aurelia.register(DateFormatValueConverter) /* ... */;

// --- my-component.ts ---
import { customElement } from 'aurelia';
import { DateFormatValueConverter } from './date-format';
// Incorrect: Duplicate local registration
// @customElement({ name: 'my-component', template: '<p>${today | dateFormat}</p>', dependencies: [DateFormatValueConverter, DateFormatValueConverter] })
// export class MyComponent { today = new Date(); }

// Correct: Register locally only once (if not registered globally)
// @customElement({ name: 'my-component', template: '<p>${today | dateFormat}</p>', dependencies: [DateFormatValueConverter] })
// export class MyComponent { today = new Date(); }

Debugging Tips

  • Search your project for the converter name (<converter-name>) from the warning to find all @valueConverter usages with that name.

  • Check global registrations in main.ts.

  • Inspect dependencies arrays in component/element definitions.

  • Verify naming conventions if used.

Last updated

Was this helpful?