The problem is in the following line:
.filter(dm => dm.structureTypeName === 'MyFirstModule')[0];
The property 'structureTypeName' contains a textual representation of the type of the object. In this case, it will always be "DomainModels$DomainModel", as you are filtering domain models. As the result of filtering will be an empty array, taking the first element of that will yield 'undefined', which causes the error you get later on.
It looks like you want to get the domain model for the module called 'MyFirstModule'. If you change the line to the following, it should work:
.filter(dm => dm.containerAsModule.name === 'MyFirstModule')[0]