如何将Nightmarejs导入到angular-cli组件中

我要用Electron&Nightmare制作GUI刮板。 但是,当我使用电子quickstart中描述的纯html / js,一切运作良好。 但是我想通过使用Anugular2(angular-cli webpack)很好地制作Electron应用程序。 我创build了ng new Scrapper然后为组件创build了一些路线,例如HomeComponentSettingsComponent 。 我安装噩梦angular度项目文件夹中的npm install --save nightmare ,我想导入它在SettingsComponent如:

 import {Nightmare} from 'nightmare'; 

并使用它像:

 ngOnInit{ this.nightmare = new Nightmare({ show: true, electronPath: require('node_modules/electron') }) } 

我有什么尝试:

1)在index.html中包含

<script src="node_modules/nightmare/lib/nightmare.js"></script>

2)然后在我的组件

 declare var Nightmare: any; 

3)ngOnInit(){

 this.nightmare = new Nightmare({}) 

4)获取有关在node_modules/nightmare/lib/*.js丢失其他js文件的错误

码:

 index.html <!doctype html> <html> <head> <meta charset="utf-8"> <title>Scrap</title> <base href="/"> <link rel="stylesheet" href="assets/semantic.min.css"> <script src="assets/require.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> <body> <app-root>Loading...</app-root> </body> </html> component: import { Component, OnInit } from '@angular/core'; declare var require: any; var Nightmare = require('nightmare'); @Component({ selector: 'app-work', templateUrl: './work.component.html', styleUrls: ['./work.component.css'] }) export class WorkComponent implements OnInit { constructor() { } ngOnInit() { } } 

错误:

 Failed to compile. ./~/nightmare/lib/nightmare.js Module not found: Error: Can't resolve 'child_process' in 'C:\Users\admin\Desktop\Scrap\node_modules\nightmare\lib' @ ./~/nightmare/lib/nightmare.js 18:11-35 @ ./src/app/work/work.component.ts @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts 

电子应用程序内的Angular2 / Nightmare是否可以互动?