Support optional dependencies in the module loader (see #6835)