I had the same error. For me, I traced this in an error on the platforms / ios / cordova / node_modules / ios-sim / src / lib.js
getdevicetypes: function(args) { ... list.devicetypes.forEach(function(device) { name_id_map[ filterDeviceName(device.name) ] = device.id; }); list = []; var remove = function(runtime) {
The error always occurred as "TypeError: unable to read the" replace "property from undefined" in lib.js: 289
list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));
So, I inserted the debug code:
list.devicetypes.forEach(function(device) { console.log('test 1 ' + device.name); console.log('test 2 ' + filterDeviceName(device.name)); name_id_map[ filterDeviceName(device.name) ] = device.id; });
It worked for me. Good luck.
list = []; var remove = function(runtime) { // remove "iOS" prefix in runtime, remove prefix "com.apple.CoreSimulator.SimDeviceType." in id console.log('remove 1 ' + runtime); console.log('remove 2 ' + deviceName); console.log('remove 3 ' + name_id_map[ deviceName ]); list.push(util.format('%s, %s', name_id_map[ deviceName ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, ''))); };
and got the following output:
test 1 iPhone 5 test 2 iPhone 5 test 1 iPad Pro (9.7-inch) test 2 iPad Pro (9.7 inch) remove 1 iOS 10.2 remove 2 iPhone 5 remove 3 com.apple.CoreSimulator.SimDeviceType.iPhone-5 remove 1 iOS 10.2 remove 2 iPad Pro (9.7-inch) remove 3 undefined
Note that filterDeviceName removed the minus character while filling the hash. When the value is restored again, the filter will not be applied, and the program will end with an error.
Fix bug: apply filter while writing and reading from hash.
list.push(util.format('%s, %s', name_id_map[ filterDeviceName(deviceName) ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));