現在、アプリ コンポーネント レベルで HTTP_PROVIDERS を設定しています。./node_modules/.bin/ngc 経由でコンパイラを実行すると、エラーが表示されます。
コンパイラを実行するときの完全なエラーは次のとおりです。
Error: Error at /Users/girishnanda/Documents/offlinecompiler/src/app.component.ngfactory.ts:47:33: Module '"/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/http/http"' has no exported member 'HTTP_PROVIDERS'.
Error at /Users/girishnanda/Documents/offlinecompiler/src/app.component.ngfactory.ts:51:38: Module '"/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/http/http"' has no exported member 'HTTP_PROVIDERS'.
Error at /Users/girishnanda/Documents/offlinecompiler/src/app.component.ngfactory.ts:53:77: Cannot use 'new' with an expression whose type lacks a call or construct signature.
at check (/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/compiler-cli/tsc.js:32:15)
at Tsc.typeCheck (/Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/compiler-cli/tsc.js:67:9)
at /Users/girishnanda/Documents/offlinecompiler/node_modules/@angular/compiler-cli/main.js:39:23
at process._tickCallback (node.js:406:9)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:141:18)
at node.js:933:3
Compilation failed
HTTP_PROVIDERS を設定しているアプリ コンポーネント
import {Component} from '@angular/core';
import {HTTP_PROVIDERS} from '@angular/http';
@Component({
selector: 'app',
template: `test
`,
providers: [HTTP_PROVIDERS]
})
export class AppComponent {
constructor() { }
}
使用される Compiler、Compile-cli、typescript、および @angular/http のバージョン
"@angular/compiler": "2.0.0-rc.1",
"@angular/compiler-cli": "0.2.0",
"@angular/http": "2.0.0-rc.1",
"typescript": "^1.9.0-dev.20160605-1.0"
Tsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"outDir": "built",
"noImplicitAny": false
},
"exclude": [
"typings/main.d.ts",
"typings/main",
"node_modules"
]
}
Typings.json
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
"jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
"node": "registry:dt/node#4.0.0+20160509154515"
}
}
HTTP_PROVIDERS を含めない場合、コンパイルはエラーなしで正常に実行されます。HTTP_PROVIDERS でコンパイルできるように、何を変更する必要があるかについてのガイダンスは役に立ちます。
ブートストラップにプロバイダーを追加しようとするコメントへの返信。これは私のmain.tsです。追加のプロバイダーを追加する方法をまだ理解していません。これは、オフライン コンパイラを使用した基本的な例です。
import {coreBootstrap, ReflectiveInjector, enableProdMode} from '@angular/core';
import {browserPlatform, BROWSER_APP_COMMON_PROVIDERS, BROWSER_APP_STATIC_PROVIDERS} from '@angular/platform-browser';
import {AppComponentNgFactory} from './app.component.ngfactory';
import {AppComponent} from './app.component';
enableProdMode();
const appInjector =
ReflectiveInjector
.resolveAndCreate(BROWSER_APP_COMMON_PROVIDERS, browserPlatform().injector);
coreBootstrap(appInjector, AppComponentNgFactory);