2016-11-06 2 views
2

렌더러 프로세스에서 내부 모듈을 요구할 수 없습니다. 내부 노드 모듈 또는 전자를 필요로 할 때 오류 또는 정의되지 않거나 빈 객체가 있습니다. 예를 들어전자 각도 2 (angular-cli)가 내부 모듈에 오류가 발생했습니다.

:

여기
import * as fs from 'fs'; 
console.log(fs) // empty object 

import { spawn } from 'child_process'; // Can't find child_process module 

import * as electron from 'electron' // fs.readFileSync is not a function 

내 코드입니다 : 내가 잘못

import { Component } from '@angular/core'; 
import { readdirSync } from 'fs'; 
import { spawn } from 'child_process'; 
console.log(readdirSync); 
@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.styl'] 
}) 
export class AppComponent { 
    constructor() {} 
} 

을하고 있어요 무엇 : 전자

import { app, BrowserWindow } from 'electron'; 
let mainWin = null; 
const loadURL = `http://localhost:4200`; 
const createWindow =() => { 
    mainWin = new BrowserWindow({ 
     width: 800, 
     height: 800 
    }); 
    mainWin.loadURL(loadURL); 
    mainWin.on('closed',() => { 
     mainWin = null; 
    }); 
} 
app.on('ready', createWindow); 
app.on('activate',() => { 
    if (!mainWin) { 
     createWindow(); 
    } 
}); 

및 렌더링 과정 각도 코드는?

답변

0

브라우저 용 Angular로 서버 측 모듈을 포함합니다.

전자는 NodeJS를 필요로합니다. 브라우저는 서버가 할 수있는 파일 시스템에만 액세스 할 수 없습니다.

하지만 당신은 index.html 파일

당신의 각도 응용 프로그램에서 전자의 부품을 사용하는 예를 통해 전자를 요구할 수 있도록 전자는 노드를 사용하여 index.html 파일을 렌더링합니다.

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Angular App</title> 
    <base href="./"> 

    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 


</head> 
<body> 
    <app-root></app-root> 


    <script> 
    window.electron = require("electron"); 
    window.ipcRenderer = require("electron").ipcRenderer; 
    window.electronRemote = require("electron").remote; 
    </script> 


</body> 
</html> 
+0

이 방법을 사용하는 것이 좋습니다. – cocoseis

+0

당신의 빌드 시스템에 따라 다르다고 생각합니다. 일부는 매우 제한적입니다. 나는 이것이 각도 cli 빌드를 사용하여 전자로 작업하는 가장 버그없는 방법이라는 것을 알았다. –

+0

누락 된 입력 내용은 어떻게됩니까? – cocoseis

관련 문제