0
四處錯誤:錯誤需要( 'child_process')沒有定義的函數 - 打字稿
zone.js:260 Uncaught EXCEPTION: Error in ./AppComponent class AppComponent - inline template:8:48
ORIGINAL EXCEPTION: ReferenceError: require is not defined
ORIGINAL STACKTRACE:
ReferenceError: require is not defined
at AppComponent.performCmdOperation (http://localhost:8000/app/app.component.js:43:67)
和 app.component.ts是
export class AppComponent{
SelectType = EnumSelectType;
selectedSection: SelectType = EnumSelectType[EnumSelectType.Home];
selectPage(selectType:EnumSelectType) {
console.log('Global : ' + EnumSelectType[selectType]);
this.selectedSection = EnumSelectType[selectType];
console.log(this.selectedSection + ' selected');
}
performCmdOperation(){
console.log('in perform action');
const exec = require('sdk/system/child_process').exec; //this is the point where I'm getting error.
exec('ipconfig', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
}
請幫我找出這個問題。使用'child_process'是否需要import missing or any dependency
。
我現在的依賴是
"bootstrap": "^3.3.6",
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",
"@angular/upgrade": "2.0.0-rc.4",
"systemjs": "0.19.27",
"es6-shim": "^0.35.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12"
如果這是它需要修改gulpfile.ts東西。請指導如何在gulpfile中添加「child_process」。
我正在使用gulp來編譯這一切,所以如果你可以幫助我使用gulp任務函數在應用程序中使用它,這將有助於。 –
同樣在這裏,我爲我的構建使用gulp,並使用'child_process'來調用外部可執行文件。我會用一個例子更新我的答案。不過,您不會在Angular 2組件中使用它。 –
請儘可能使用gulpfile.js任務示例提供示例。謝謝! –