I am trying to push a managed extension package to a scratch org but am running into some issues. The issues seem to be stemmed around some custom objects that are owned by the package that is being extended. I have added the "extension" fields and can see that the objects are being added to the extension package but it is still erroring. Any suggestions?
In case anyone else ends up here, I hit the same issue today and spent a long time trying different approaches until I found one this one that seems to have worked.
I created a scratch org with the namespace for the extension package, and added the package it extends i.e the master package. That master package contains a custom object and some fields which I use in my child package, and I also add some fields to it in my child package.
I then converted the metadata of the extension package into the DX format, and added the code to my DX project for the extension package. Note - although I could see the fields and reference to the custom object in my master package in the DX source, if I tried to push at this point it failed.
So I then edited the custom object from my master package in my new scratch org (I enabled Track Activities), and did a force source pull with -f param to force the metadata to come down. At that point, DX not only retrieved all the fields on the the custom object into my source, it also updated the metadata for the object definition. At this point, I was then able to push the metadata to my scratch org.
Looking at the metadata, I suspect I could just copy the metadata definition from the DX project for that object from my master package and it would work (it looks the same at first glance), so I think this just an issue with the way the DX metadata is retrieving objects from the packaging org when your package has a dependency on another package.
One other thing I noted was that I have custom fields on Account and other standard objects, but in those cases there is no object definition in the directory for that object so it seems to be something specific to referencing a custom object in a separate managed package.