Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点';s和电子';s模块从内部角度2_Node.js_Angular_Typescript_Electron - Fatal编程技术网

Node.js 节点';s和电子';s模块从内部角度2

Node.js 节点';s和电子';s模块从内部角度2,node.js,angular,typescript,electron,Node.js,Angular,Typescript,Electron,我正在使用Angular2开发一个Electron应用程序 在electron的main.js中,我正在引用/加载NG应用程序: const {app, BrowserWindow} = require('electron') const path = require('path') const url = require('url') let win function createWindow () { win = new BrowserWindow({width: 800, heig

我正在使用Angular2开发一个Electron应用程序

在electron的
main.js
中,我正在引用/加载NG应用程序:

const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

let win

function createWindow () {
  win = new BrowserWindow({width: 800, height: 600})

  // load the index.html of the NG app:
  win.loadURL(url.format({
    pathname: path.join(__dirname, '/../../dist/index.html'),
    protocol: 'file:',
    slashes: true
  }))

[...]
这很有魅力。但是,我现在想从NG部件内部访问node和electron的模块

当我尝试导入时,例如:
fs
模块,如:

import * as fs from "fs";
它仍然可以编译,但每当我调用
fs.readFile(…)
时,它都会显示:

__WEBPACK_IMPORTED_MODULE_2_fs__.readFile is not a function
仔细想想,这不起作用,也不可能起作用,因为模块不在
node\u modules
文件夹中(对吗?)。
我需要做什么才能使它们在NG部件内部可用?

您不能直接从内部调用电子/节点模块。相反,请检查。

以防这仍然相关-

我还不知道有什么“官方”的方法来解决这个问题。但也有一些变通解决方案——主要是在index.html中要求使用electron/其他模块和访问
窗口['electron']
-

<script>
    window.electron = require('electron');
</script>
你可以看到这个的一个实现

  • ElectronWindow
    指的是一个自定义界面,您可以创建并添加require()函数来处理打字
  • 使用
    窗口。需要(*某些节点模块*)
    来存储模块

不幸的是,我甚至无法访问
electron
模块来从以下位置加载
remote
import{remote}from“electron”抛出:
找不到名称“electron”
declare const window: ElectronWindow;
export class ChildProcessService {...}