如何将Angular2与JSPM一起使用?
我一直在JSPM(v17)中使用Angular2,但我能让它工作的唯一方法是将typescript配置为将我的模块编译为如何将Angular2与JSPM一起使用?,angular,typescript,jspm,Angular,Typescript,Jspm,我一直在JSPM(v17)中使用Angular2,但我能让它工作的唯一方法是将typescript配置为将我的模块编译为commonjs。但是,在执行此操作时,我始终会看到每个文件的以下警告: TopeScript [警告]转储到Cuffjs,考虑在Type Script中设置模块:“Stand”,以便直接转换到Stase.Relphi格式 当我将模块设置为system时,出现以下运行时错误: TypeError:无法读取未定义的属性“forRoot” 这是从这段代码中抛出的: import
commonjs
。但是,在执行此操作时,我始终会看到每个文件的以下警告:
TopeScript [警告]转储到Cuffjs,考虑在Type Script中设置模块:“Stand”,以便直接转换到Stase.Relphi格式
当我将模块设置为system
时,出现以下运行时错误:
TypeError:无法读取未定义的属性“forRoot”
这是从这段代码中抛出的:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const appRoutes: Routes = [
{ path: '', redirectTo: '/login', pathMatch: 'full' },
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
如果我从项目中删除路由模块,我最终会看到以下错误:
核心组件不是一个函数
关于我的AppComponent
:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>hello world</h1>`,
})
export class AppComponent { }
我还尝试将所有@angular
包的格式重写为esm
,但随后我看到以下运行时错误:
无法添加属性ng,对象不可扩展
commonjs
是唯一的方法还是我缺少设置?来自:
是的,这是SystemJS 0.20中的一个变化,其中命名为非ES的导出
为了与互操作方式保持一致,不再支持模块
将在ES模块和CommonJS之间的NodeJS中工作,这仅限于
提供与默认导入表单-导入模块的兼容性
来自'module'(相当于从导入{default as module}
“模块”)
为了包含带有命名导出的CommonJS模块,我需要为每个angular库添加一个覆盖,包括任何其他属于CommonJS的第三方库
"meta": {
"*.js": {
"esModule": true
}
}
目前,似乎最好将typescript设置为使用commonjs
作为模块系统
"meta": {
"*.js": {
"esModule": true
}
}