Fix build system to use module maps

Fixes #18102.

(cherry picked from commit 6ad2af6c7cc33e061feb0364274e27bacb7e880e)