我一直在使用Angular2和JSPM(v17),但唯一能讓它工作的方法是配置打字稿來編譯我的模塊爲commonjs
。然而,在這樣做時,我總是看到每個文件以下警告:如何在JSPM中使用Angular2?
TypeScript [Warning] transpiling to CommonJS, consider setting module: "system" in typescriptOptions to transpile directly to System.register format
當我設置模塊system
我得到以下運行時錯誤:
TypeError: Cannot read property 'forRoot' of undefined
正在被從該位拋出代碼:
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 { }
如果我從項目中刪除我的路由模塊,我最終看到以下錯誤:
core_1.Component is not a function
圍繞我AppComponent
:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>hello world</h1>`,
})
export class AppComponent { }
顯然,任何角度進口回來的null
。
這裏是我的tsconfig.json
:
{
"compilerOptions": {
"target": "es2016",
"module": "system",
"moduleResolution": "node",
"inlineSourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"jspm_packages"
]
}
我也試着重寫所有@angular
包格式esm
,但後來我看到以下運行時錯誤:
Can't add property ng, object is not extensible
是commonjs
唯一路要走還是我想念一個設置?