[backend] fix handling of replaced packages in package imports

The old code could not deal with multiple packages having the same name.
Thanks go to UkJung Kim for reporting this.