MlinkRequests
Bun

method

vm.SourceTextModule.linkRequests

modules: readonly Module[]
): void;

Link module dependencies. This method must be called before evaluation, and can only be called once per module.

The order of the module instances in the modules array should correspond to the order of sourceTextModule.moduleRequests being resolved. If two module requests have the same specifier and import attributes, they must be resolved with the same module instance or an ERR_MODULE_LINK_MISMATCH would be thrown. For example, when linking requests for this module:

import foo from 'foo';
import source Foo from 'foo';

The modules array must contain two references to the same instance, because the two module requests are identical but in two phases.

If the module has no dependencies, the modules array can be empty.

Users can use sourceTextModule.moduleRequests to implement the host-defined HostLoadImportedModule abstract operation in the ECMAScript specification, and using sourceTextModule.linkRequests() to invoke specification defined FinishLoadingImportedModule, on the module with all dependencies in a batch.

It's up to the creator of the SourceTextModule to determine if the resolution of the dependencies is synchronous or asynchronous.

After each module in the modules array is linked, call sourceTextModule.instantiate().

@param modules

Array of vm.Module objects that this module depends on. The order of the modules in the array is the order of sourceTextModule.moduleRequests.