AUR0116
Error Message
AUR0116: Ast eval error: cannot assign value to property "<property>" of null/undefined.
Where <property> is the name or key of the property being assigned to.
Description
This error occurs during the evaluation of a binding expression when an attempt is made to assign a value to a property (using dot notation like obj.prop = value or bracket notation like obj[key] = value), but the base object (obj in the examples) is currently null or undefined. JavaScript prevents assigning properties to null or undefined.
Cause
The most common reasons for this error are:
Object Not Initialized: The object whose property you are trying to set has not been initialized or has been explicitly set to
nullorundefined.Asynchronous Initialization: The object is intended to be initialized by an asynchronous operation (e.g., fetching data), but the assignment attempt happens before the operation completes and the object is assigned.
Incorrect Property Access Path: The expression leading to the object might be incorrect, resulting in
nullorundefinedbeing evaluated before the final property assignment (e.g.,data.user.name = 'Test'whendata.userisnull).Conditional Logic: The object might exist under certain conditions but be
nullorundefinedunder others, and the assignment occurs when it doesn't exist.
Solution
Ensure Initialization: Initialize the object before attempting to assign properties to it. This can be done in the view model's constructor, appropriate lifecycle hooks (
binding,bound,attaching), or using default values.Conditional Assignment: Use conditional logic (
if.bindin the template orifstatements in the view model) to ensure the assignment only happens when the object is notnullorundefined.Default Values: Provide default objects in the path if parts might be nullish, for example
data.user = data.user || {}; data.user.name = 'Test';. Be cautious with this approach as it might hide underlying issues.Await Asynchronous Operations: If the object is initialized asynchronously, ensure that any logic attempting property assignments waits for the initialization to complete (e.g., using
async/awaitor Promise chaining).
Example
Debugging Tips
Use
console.logor breakpoints to inspect the value of the object immediately before the property assignment that causes the error.Trace back the code execution to find where the object should have been initialized or why it became
nullorundefined.Check asynchronous operations (API calls, timeouts) that might be responsible for initializing the object and ensure they complete before assignments occur.
Verify the full property access path (e.g.,
a.b.c) - ensure that intermediate objects (aanda.b) are also notnullorundefinedif you are assigning toc. Consider optional chaining (a.b?.c = value) if appropriate, though this prevents the assignment ifa.bis nullish, which might not be the desired outcome. Direct assignment as in the error requires the path to exist.
Last updated
Was this helpful?