首页 > 解决方案 > 无法解析“fs”或“路径”Edge-js 和 Angular

问题描述

我正在使用 electron-edge-js 制作一个 Electron Angular 应用程序,以避免必须运行服务器来在 Angular 和 C# 代码之间进行转换。只要我实际上没有调用 edge 做任何事情,该应用程序就可以工作,但是(在构建时)失败:

Module not found: Error: Can't resolve 'fs' (or 'path') in ... node_modules\electron-edge-js\lib.

我已经尝试了所有可以在网上找到的解决方案。我使用了 angular-builders\custom-webpack 并能够构建应用程序,但我得到的下一个错误是“未定义要求”。

代码可以在这里找到:https ://github.com/pdpete/AngularElectronEdgeQuickstart

在 app.component.ts 中:

import { Component } from '@angular/core';
import * as Edge from 'electron-edge-js';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'The Wrong App Name';

  // if this is commented out, the app works fine, but with 'The Wrong App Name'
  constructor() {
    var getAppName = Edge.func({
      assemblyFile: "Controller.dll",
      typeName: "Controller.NameController",
      methodName: "GetName"
    });

    getAppName(null, function (error, result) {
      if (error) throw error;
      console.log(result);
      this.title = result;
    });
  }
}

标签: c#angularelectronedgejs

解决方案


据我所知,经过大量研究,Angular 5 及以上版本不允许访问 fs(或其他节点模块),因此无法编写 Angular 版本 > 5 的 Edge 应用程序。


推荐阅读