Thanks for offering the sample project! That really helps to see the issue you're running into.
So this behaves correctly because when previewing in a static library all by itself there is no main bundle. When building and running this within the context of an app target using Bundle.main
will work just fine, of course because everything is loaded together in memory. But in the context of previewing a single package by itself, Previews is able to launch its own empty app and inject the package library into it. Bundle.main
will point to that app bundle.
The advice above to make sure you put the resources you want into the package is a good idea to resolve this. It may be possible to work around this by always previewing the package library when you have the app target selected in the scheme, but that still is working around a circular dependency that is best resolved by making sure the app target code depends on library resources and not the other way around.