I'm having the same problems. Trying to get this to work so I don't have to re-assign layer IDs in various places in WAB code.
The error I'm getting occurs at line 100 in LayerInfoForDefaultDynamic.js :
if (objLayerInfos[currentId].parentLayerId === -1) {
When I reorder the layers in a map service, the value of currentId matches the unique numeric ID I have set in the MXD before publishing. If I have 10 layers, for example, and add an 11th layer between layers 3 and 4, the value of currentId is 11. In the objLayerInfos array, however, index 11 still refers to the last layer in the map service (which would have the unique sub layer id 10) instead of the 4th layer in the map service. I think this is where the problem is happening, but I'm not sure how it could be resolved, or if similar problems are being caused elsewhere.