in src/core/moduleManager.ts [782:830]
private _loadModule(moduleId: ModuleId): void {
if (this._modules2[moduleId] || this._knownModules2[moduleId]) {
// known module
return;
}
this._knownModules2[moduleId] = true;
let strModuleId = this._moduleIdProvider.getStrModuleId(moduleId);
let paths = this._config.moduleIdToPaths(strModuleId);
let scopedPackageRegex = /^@[^\/]+\/[^\/]+$/ // matches @scope/package-name
if (this._env.isNode && (strModuleId.indexOf('/') === -1 || scopedPackageRegex.test(strModuleId))) {
paths.push('node|' + strModuleId);
}
let lastPathIndex = -1;
let loadNextPath = (err: any) => {
lastPathIndex++;
if (lastPathIndex >= paths.length) {
// No more paths to try
this._onLoadError(moduleId, err);
} else {
let currentPath = paths[lastPathIndex];
let recorder = this.getRecorder();
if (this._config.isBuild() && currentPath === 'empty:') {
this._buildInfoPath[moduleId] = currentPath;
this.defineModule(this._moduleIdProvider.getStrModuleId(moduleId), [], null, null, null);
this._onLoad(moduleId);
return;
}
recorder.record(LoaderEventType.BeginLoadingScript, currentPath);
this._scriptLoader.load(this, currentPath, () => {
if (this._config.isBuild()) {
this._buildInfoPath[moduleId] = currentPath;
}
recorder.record(LoaderEventType.EndLoadingScriptOK, currentPath);
this._onLoad(moduleId);
}, (err) => {
recorder.record(LoaderEventType.EndLoadingScriptError, currentPath);
loadNextPath(err);
});
}
};
loadNextPath(null);
}