Error when exporting Lua to RV50

The IDE indeed need port 1999 and 22 for local access.
To have ssh access (port 22) on the wan interface you may need to configure ALEOS (22 might not be the default).
Other than that I see no reason why it does not work (especially if you can already make it work with a public IP from the WWAN interface)

An alternative/workaround could be use the ACEmanager UI to actually install your AAF application. That is available starting from ALEOS 4.8.0. In that case you do not need to open specific ports (beside ACEmanager http/https dedicated port).
To generate an ACEmanager-installable package from the IDE you would use the export feature (the same as you mention) but set output to the local filesystem instead from a device IP.