NativeScript/NativeScript · error · Error
element cannot be null or undefinied.
Error message
element cannot be null or undefinied.
What it means
FlexboxLayout's static attached-property helpers (setOrder/getOrder, setFlexGrow/getFlexGrow, setFlexShrink/getFlexShrink) require a View instance. validateArgs throws when the element argument is null or undefined.
Source
Thrown at packages/core/ui/layouts/flexbox-layout/flexbox-layout-common.ts:139
}
}
export type AlignSelf = 'auto' | AlignItems;
export namespace AlignSelf {
export const AUTO = 'auto';
export const FLEX_START = 'flex-start';
export const FLEX_END = 'flex-end';
export const CENTER = 'center';
export const BASELINE = 'baseline';
export const STRETCH = 'stretch';
export const isValid = makeValidator<AlignSelf>(AUTO, FLEX_START, FLEX_END, CENTER, BASELINE, STRETCH);
export const parse = makeParser<AlignSelf>(isValid);
}
function validateArgs(element: View): View {
if (!element) {
throw new Error('element cannot be null or undefinied.');
}
return element;
}
/**
* A common base class for all cross platform flexbox layout implementations.
*/
@CSSType('FlexboxLayout')
export abstract class FlexboxLayoutBase extends LayoutBase {
get flexDirection(): FlexDirection {
return this.style.flexDirection;
}
set flexDirection(value: FlexDirection) {
this.style.flexDirection = value;
}
get flexWrap(): FlexWrap {View on GitHub (pinned to 6800aefa65)
Solutions
- Ensure a real View is passed to all six helpers
- Check getViewById()/lookups for undefined before use
- Guard calls with if (child)
Example fix
// before
FlexboxLayout.setOrder(container.getViewById('a'), 2);
// after
const a = container.getViewById('a');
if (a) {
FlexboxLayout.setOrder(a, 2);
} Defensive patterns
Strategy: type-guard
Validate before calling
const child = flexbox.getViewById('item');
if (child != null) {
FlexboxLayout.setOrder(child, 1);
FlexboxLayout.setFlexGrow(child, 1);
} Type guard
function isNonNull<T>(v: T | null | undefined): v is T {
return v != null;
} Try / catch
try {
FlexboxLayout.setFlexGrow(child, 2);
} catch (e) {
if (String(e.message).includes('element cannot be null')) {
// re-resolve or skip child
}
} Prevention
- Null-check results of getViewById before attached-property calls
- Set flex attached properties after children exist in the tree
- Assert child presence in dev with console.assert(child != null)
When it happens
Trigger: FlexboxLayout.setOrder(null, 1), getFlexGrow(undefined), setFlexShrink(view-not-loaded, 0); passing result of a failed getViewById().
Common situations: Configuring flex children before they are added/looked up; variables cleared after view removal; copy-paste calling helpers with the wrong variable.
Related errors
- element cannot be null or undefinied.
- element cannot be null or undefinied.
- source is null or undefined
- target is null or undefined
- eventName is not a string
AI-assisted analysis of NativeScript/NativeScript@6800aefa65 (2026-08-30).
Data as JSON: /api/errors/24e4c2dd55810a6d.
Report an issue: GitHub.