After some fiddling I figured out that if I abstracted the middlewear code into it's own swift package library I could get it to compile outside Xcode and them import the library into Xcode. It's possible there was some sort of namespace collision, but even explicitly specifying the module for each type didn't solve it so I'm still not sure what was going on. Any insights would be appreciated for future learning.