【发布时间】:2019-04-18 18:17:53
【问题描述】:
我正在使用 systemjs 创建一个 Angular 7 项目以动态加载模块。
当我尝试使用它时,我遇到了这个错误:
ERROR ReferenceError: SystemJS is not defined
我的 package.json 包含 systemjs: 2.1.1
我在 angular.json 中添加了 systemjs 路径到部分脚本
"./node_modules/systemjs/dist/system.js"
我声明 SystemJs 在我的服务中使用它:
declare const SystemJS;
我正在尝试像这样在这个函数中使用:
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;
});
});
}
也许我错过了什么,
你能帮帮我吗?
【问题讨论】:
-
即使使用 systemjs@0.21.5 我也遇到了同样的问题,但只有在 --prod 模式下构建时,当我使用 ng serve 时,它才能按预期工作。你能指定你遇到错误的模式吗?
标签: angular typescript systemjs angular7