c# - 无法解析“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;
});
}
}
解决方案
据我所知,经过大量研究,Angular 5 及以上版本不允许访问 fs(或其他节点模块),因此无法编写 Angular 版本 > 5 的 Edge 应用程序。
推荐阅读
- javascript - React useState:将子数组推入数组
- git - 如何在 vscode 中使用 ssh 克隆私有 git 存储库?
- javascript - 如何使用异步方法制作正确的 Singleton 类?(TS/JS)
- javascript - 错误地识别重复的参数名称?
- android - 在 Cordova 中获取平台 cordova-android@^8.0.0 失败
- python - 使用 PyPi 通过 git clone 传递令牌的正确方法是什么?
- loops - 如何在特定点循环 ROBLOX 音频?
- c++ - 当我在 Visual Studio Code for C++ 中从 gerrit 中提取代码时,缩进会中断
- qt - 打开下拉菜单后在 QtWebEngine 中触摸冻结
- vba - 有一个列表框,用于过滤我的子表单中作为查询的项目