I solved it by clearing all the build cache/files in the same directory where the source code was in, and then ran the flet build command through the Developer Command Prompt for VS 2022.