Correctly resolve the module dependencies (see #6606)