n8n-io/n8n · error · ExpressionExtensionError
Unsupported unit '${String(errorUnit)}'. Supported: ${durati
Error message
Unsupported unit '${String(errorUnit)}'. Supported: ${durationUnits.map((u) => `'${u}'`).join(', ')}. What it means
`.diffTo(other, unit)` accepts a duration unit (or an array of units) drawn from the union of `dateParts` (`day`,`week`,`month`,`year`,`hour`,`minute`,`second`,...) and `durationUnits` (`milliseconds`,`seconds`,`minutes`,`hours`,`days`,`weeks`,`months`,`quarters`,`years`). The first element outside that set triggers the throw and the message echoes the supported list. Note the message lists only `durationUnits`, but singular `dateParts` are also accepted.
Source
Thrown at packages/@n8n/expression-runtime/src/extensions/date-extensions.ts:247
if (isDateTime(date)) return date.plus(duration);
return DateTime.fromJSDate(date).plus(duration).toJSDate();
}
function diffTo(date: DateTime, args: [string | Date | DateTime, DurationUnit | DurationUnit[]]) {
const [otherDate, unit = 'days'] = args;
let units = Array.isArray(unit) ? unit : [unit];
if (units.length === 0) {
units = ['days'];
}
const allowedUnitSet = new Set([...dateParts, ...durationUnits]);
const errorUnit = units.find((u) => !allowedUnitSet.has(u));
if (errorUnit) {
throw new ExpressionExtensionError(
`Unsupported unit '${String(errorUnit)}'. Supported: ${durationUnits
.map((u) => `'${u}'`)
.join(', ')}.`,
);
}
const diffResult = date.diff(toDateTime(otherDate), units);
if (units.length > 1) {
return diffResult.toObject();
}
return diffResult.as(units[0]);
}
function diffToNow(date: DateTime, args: [DurationUnit | DurationUnit[]]) {
const [unit] = args;
return diffTo(date, [DateTime.now(), unit]);View on GitHub (pinned to 5ac6606e81)
Solutions
- Use one of the supported units shown in the error message (e.g. `days`, `hours`, `minutes`, `seconds`, `months`, `years`).
- When passing an array, ensure every element is in the allowed set.
- If you need a unit n8n does not expose, compute the diff in a Code node using Luxon directly.
Example fix
// before
{{ $json.start.diffTo($json.end, 'fortnights') }}
// after
{{ $json.start.diffTo($json.end, 'days') }} Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = new Set([
'milliseconds','seconds','minutes','hours','days','weeks','months','quarters','years',
'day','week','month','year','hour','minute','second'
]);
const unit = $json.unit;
const units = Array.isArray(unit) ? unit : [unit];
const bad = units.find((u) => !ALLOWED.has(u));
if (bad) throw new Error(`Unsupported diffTo unit: ${bad}`);
return $json; Type guard
const isSupportedUnit = (u: string): boolean => ['milliseconds','seconds','minutes','hours','days','weeks','months','quarters','years','day','week','month','year','hour','minute','second'].includes(u);
Prevention
- Prefer plural duration forms (`days`, `hours`) for diffs.
- When passing a unit array, validate every element against the allowed set.
- Compute exotic units in a Code node with Luxon directly.
When it happens
Trigger: Using singular-but-unsupported or misspelled units: `.diffTo(other, 'fortnight')`, `.diffTo(other, 'dayss')`, or `.diffTo(other, ['days', 'centuries'])`.
Common situations: Assuming Luxon's full unit catalogue is accepted; using the wrong singular/plural form (e.g. `'day'` works via dateParts but `'days'` is the duration form); typos.
Related errors
- Unsupported format '${String(valueFormat)}'. toDateTime() su
- intersection(): expected array arg, e.g. .intersection([1, 2
- isBetween(): expected exactly two args
- keys and values must be arrays
- keys and values not of equal length
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/474581ea44f81af8.
Report an issue: GitHub.