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任务示例提供示例。谢谢! –