TWRP fails to flash stock ROM (invalid zip)
I encountered this too:

build/tools/releasetools/sign_target_files_apks -o -d "$KEY_DIR" out/target/product/$DEVICE/obj/PACKAGING/target_files_intermediates/aosp_$DEVICE-target_files-eng.xx.zip $OUT/$TARGET_FILES

build/tools/releasetools/ota_from_target_files --block -k "$KEY_DIR/releasekey" $OUT/$TARGET_FILES  $OUT/$DEVICE-ota_update-$BUILD.zip

build/tools/releasetools/img_from_target_files -v $OUT/$TARGET_FILES $OUT/$DEVICE-img-$BUILD.zip


TWRP will install $DEVICE-ota_update-$BUILD.zip, but failed to install $DEVICE-img-$BUILD.zip: Failed to install, invalid zip file format!. fastboot update $OUT/$DEVICE-img-$BUILD.zip works.

TWRP version twrp-3.1.1-0-grouper