HYSIRY branded WEMOS D1 mini modules need to be selected as ESP8285 (not ESP8266) on ESP download tool in order to be flashed.
I had the same problem while flashing and tried several methods and firmware files to flash these modules but luckily trying ESP8285 tool (https://espressif.com/en/support/download/other-tools) the firmware flash on my first attempt successfully.
Just select ESP8285 from the start screen
and then set the path to your firmware, flash address (normally is 0x0), and COM port and baud rate (this should be up to 230400)
Hopefully some folks will be helped by this.
PANIC: unprotected error in call to Lua API (attempt to index a nil value)