我想ngc
手动运行(角度编译器-CLI)以将 TypeScript 转换为 JavaScript 代码。
包.json
{
"name": "first-angular2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "typings install"
},
"author": "",
"license": "ISC",
"dependencies": {
"@angular/common": "~2.2.3",
"@angular/compiler": "~2.2.3",
"@angular/core": "~2.2.3",
"@angular/forms": "~2.2.3",
"@angular/http": "~2.2.3",
"@angular/platform-browser": "~2.2.3",
"@angular/platform-browser-dynamic": "~2.2.3",
"@angular/router": "~3.2.0",
"@angular/upgrade": "~2.2.3",
"angular-in-memory-web-api": "~0.1.15",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"@angular/compiler-cli": "^2.1.0",
"typescript": "^2.0.10",
"@types/node": "^6.0.38",
"@types/source-map": "^0.1.27",
"@types/uglify-js": "^2.0.27",
"@types/webpack": "^1.12.34"
},
"peerDependencies": {
}
}
添加typescript
, @type
,angular
依赖项
tsconfig.json
{
"compilerOption" : {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmitHelpers": true,
"strictNullChecks": false,
"baseUrl": "./src",
"paths": {
},
"types": [
"node",
"source-map",
"uglify-js",
"webpack"
]
},
"exclude": [
"node_modules",
"dist"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"compileOnSave": false,
"buildOnSave": false,
"angularCompilerOptions": {
"genDir": ".",
"debug": true
}
}
关于要在 javascript 上转换的 typescript 的配置
错误 :
root@VSS-DT0086:/var/www/angular2/first-angular2# ./node_modules/.bin/ngc -m
Error: Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/di/reflective_provider.d.ts:88:123: Cannot find name 'Map'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/di/reflective_provider.d.ts:88:165: Cannot find name 'Map'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/facade/lang.d.ts:12:17: Cannot find name 'Map'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/facade/lang.d.ts:13:17: Cannot find name 'Set'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/application_init.d.ts:16:18: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts:24:15: Cannot find name 'Map'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts:28:16: Cannot find name 'Map'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/linker/compiler.d.ts:53:49: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/linker/compiler.d.ts:61:65: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/rxjs/Observable.d.ts:10:66: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/rxjs/Observable.d.ts:66:60: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/rxjs/Observable.d.ts:66:70: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/application_ref.d.ts:106:67: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/application_ref.d.ts:122:101: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/application_ref.d.ts:148:67: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/application_ref.d.ts:150:101: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/linker/ng_module_factory_loader.d.ts:14:34: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/linker/system_js_ng_module_factory_loader.d.ts:28:25: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/core/src/util/lang.d.ts:8:53: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/compile_metadata.d.ts:369:30: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/compile_metadata.d.ts:415:30: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/compile_metadata.d.ts:416:20: Cannot find name 'Set'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/compile_metadata.d.ts:417:15: Cannot find name 'Set'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/compile_metadata.d.ts:418:246: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/output/output_ast.d.ts:427:63: Cannot find name 'Set'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/resource_loader.d.ts:13:23: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/util.d.ts:26:18: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/util.d.ts:27:46: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/directive_normalizer.d.ts:38:72: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/directive_normalizer.d.ts:40:74: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/metadata_resolver.d.ts:62:18: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/offline_compiler.d.ts:18:32: Cannot find name 'Map'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/offline_compiler.d.ts:32:87: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/offline_compiler.d.ts:49:9: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/runtime_compiler.d.ts:44:49: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/compiler/src/runtime_compiler.d.ts:46:65: Cannot find name 'Promise'.
Error at /var/www/angular2/first-angular2/node_modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.d.ts:10:23: Cannot find name 'Promise'.
at check (/var/www/angular2/first-angular2/node_modules/@angular/tsc-wrapped/src/tsc.js:31:15)
at Tsc.typeCheck (/var/www/angular2/first-angular2/node_modules/@angular/tsc-wrapped/src/tsc.js:86:9)
at /var/www/angular2/first-angular2/node_modules/@angular/tsc-wrapped/src/main.js:33:23
at process._tickCallback (node.js:369:9)
at Function.Module.runMain (module.js:443:11)
at startup (node.js:139:18)
at node.js:974:3
Compilation failed