Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
Electron Angular应用程序,如何使用本机节点模块_Angular_Webpack_Electron_Angular Cli - Fatal编程技术网

Electron Angular应用程序,如何使用本机节点模块

Electron Angular应用程序,如何使用本机节点模块,angular,webpack,electron,angular-cli,Angular,Webpack,Electron,Angular Cli,我正在尝试使用angular制作一个电子应用程序 我遵循了教程。干得不错。 但我尝试使用本机节点模块,特别是“fs” import { Injectable } from '@angular/core'; import * as fs from 'fs'; @Injectable() export class FilesService { constructor() { } someMethod() { return fs.lstat('./'); } } 我在构建应用

我正在尝试使用angular制作一个电子应用程序

我遵循了教程。干得不错。 但我尝试使用本机节点模块,特别是“fs”

import { Injectable } from '@angular/core';
import * as fs from 'fs';
@Injectable()
export class FilesService {

  constructor() { }

  someMethod() {
    return fs.lstat('./');
  }
}
我在构建应用程序时遇到以下错误:
src/app/shared/files.service.ts(2,21)中出现错误:错误TS2307:找不到模块“fs”。


在网上冲浪一段时间后,我发现它与angular cli生成的webpack配置有关,但我不知道如何更改这些配置…

您可能需要调整webpack配置

  • 应用正确的目标()
  • 将正确的
    externals
    应用于不捆绑nodejs端模块

  • 我使用angular cli制作了这个应用程序,它通过angular-cli.json配置webpack,我是否可以覆盖生成的webpack配置,或者我是否必须推出自己的webpack配置并放弃angular cli项目?好的,所以我使用了ng eject--build and configured webpack.config`“target”:“electron renderer”,“externals”:{“fs”:require(“fs”)}`仍然不起作用。无需担心添加“target”后一切都会正常进行:“electron renderer”无需触摸外部。