Angular 7 错误参考错误:SystemJS 未定义

Tan*_*ard 5 typescript systemjs angular angular7

我正在使用 systemjs 创建一个 angular 7 项目来动态加载模块。

当我尝试使用它时,出现以下错误:

 ERROR ReferenceError: SystemJS is not defined
Run Code Online (Sandbox Code Playgroud)

我的 package.json 包含 systemjs: 2.1.1

我在 angular.json 中将 systemjs 路径添加到了部分脚本

"./node_modules/systemjs/dist/system.js"
Run Code Online (Sandbox Code Playgroud)

我声明 SystemJs 在我的服务中使用它:

declare const SystemJS;
Run Code Online (Sandbox Code Playgroud)

我正在尝试这样使用,在这个函数中:

loadModuleSystemJS(moduleInfo: ModuleData): Promise<any> {
    const url = this.source + moduleInfo.location;
    SystemJS.set('@angular/core', SystemJS.newModule(AngularCore));
    SystemJS.set('@angular/common', SystemJS.newModule(AngularCommon));
    SystemJS.set('@angular/router', SystemJS.newModule(AngularRouter));
    SystemJS.set('@angular/platform-browser/animations', SystemJS.newModule(BrowserAnimations));

    // now, import the new module
    return SystemJS.import(`${url}`).then((module) => {
      return this.compiler.compileModuleAndAllComponentsAsync(module[`${moduleInfo.moduleName}`]).then(compiled => {
        return module;
      });
    });
  }
Run Code Online (Sandbox Code Playgroud)

也许我错过了什么,

你能帮助我吗 ?

小智 5

请务必使用此版本:https : //github.com/systemjs/systemjs/releases/tag/0.21.5 2.1.1 与过去的 api 不兼容,据我所知。顺便说一下,在上面答案的示例中,使用了版本“0.21.4 Dev”。