简体   繁体   English

electronic-edge-js:无法解析fs和路径

[英]electron-edge-js: fs and path can't be resolve

I'm starting to develop with angular and I want to realized an application with electron and electron-edge.js. 我开始使用angular进行开发,并且想要实现一个带有electronic和electronic-edge.js的应用程序。

I set up the environment without issue and was able to make electron works. 我设置环境没有问题,并且能够使电子起作用。

However when I arrive to the moment I want to use electron-edge I find stop working... 但是,当我到达那一刻我想使用电子边缘时,我发现停止工作了。

These is the error I encounter: 这些是我遇到的错误:

*0] ERROR in ./node_modules/electron-edge-js/lib/edge.js
0] Module not found: Error: Can't resolve 'fs' in 'C:\Users\testbe\dev\JARVIS\n
de_modules\electron-edge-js\lib'
0] ERROR in ./node_modules/electron-edge-js/lib/edge.js
0] Module not found: Error: Can't resolve 'path' in 'C:\Users\testbe\dev\JARVIS
node_modules\electron-edge-js\lib'
0]
0] WARNING in ./node_modules/electron-edge-js/lib/edge.js 57:9-28
0] Critical dependency: the request of a dependency is an expression
0]
0] WARNING in ./node_modules/electron-edge-js/lib/edge.js 101:23-44
0] Critical dependency: the request of a dependency is an expression
0] i ?wdm?: Failed to compile.*

It's seems these error in yet fix for some people.. I have test a lot of fix found in lot of post answer but nothing seems to works. 看来这些错误尚未解决,但对某些人来说仍然可以解决。.我已经测试了很多帖子答案中发现的许多修复程序,但似乎没有任何效果。 I probably miss something. 我可能会错过一些东西。

This is the code where I call requirement that generate the issue: 这是我称为需求的代码,它会产生问题:

 declare var require: any
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'JARVIS';

  edge = require('electron-edge-js');
}


If I remove the "edge = require('electron-edge-js');"  everything works. Thus the electron-edge-js is probably the source of the issue (,well, i'm probably the source of the issue ^^ )

This is the electron.dev.js call at the beginning:

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

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

const createWindow = () => {
    // set timeout to render the window not until the Angular 
    // compiler is ready to show the project    
    setTimeout(() => {
        // Create the browser window.
        win = new BrowserWindow({
            width: 800,
            height: 600,
            icon: './src/favicon.ico'
        });

        // and load the app.
        win.loadURL(url.format({
            pathname: 'localhost:4200',
            protocol: 'http:',
            slashes: true
        }));

        win.webContents.openDevTools();
        window.require('fs');


        // Emitted when the window is closed.
        win.on('closed', () => {
            // Dereference the window object, usually you would store windows
            // in an array if your app supports multi windows, this is the time
            // when you should delete the corresponding element.
            win = null;
        });
    }, 10000);
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
    // On macOS it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
        app.quit();
    }
});

app.on('activate', () => {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (win === null) {
        createWindow();
    }
});

And the last, the start of package.json: 最后是package.json的开头:

 {"name": "jarvis",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "concurrently \"ng serve\" \"npm run electron\"",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "electron": "electron ./src/electron.dev"
  },``

Edit (based on first answer): 编辑(基于第一个答案):

I try to add 我尝试添加

    "browser": {
    "fs": false,
    "path": false,
    "os": false
}

into package.json of electron. 到电子的package.json中。 This resolve the first issue but generate a new one: 这解决了第一个问题,但产生了一个新问题:

ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'null: 0'. Current value: 'null: 1'.
at viewDebugError (core.js:7594)
at expressionChangedAfterItHasBeenCheckedError (core.js:7582)
at checkBindingNoChanges (core.js:7684)
at checkNoChangesNodeInline (core.js:10547)
at checkNoChangesNode (core.js:10534)
at debugCheckNoChangesNode (core.js:11137)
at debugCheckRenderNodeFn (core.js:11091)
at Object.eval [as updateRenderer] (AppComponent.html:6)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:11080)
at checkNoChangesView (core.js:10435)

I think the fs is necessary for electron, or not ^^ 我认为fs对于电子是必需的,或者不是^^

Where do I have to put the code below (in wich file ?): 我必须将代码放在哪里(在wich文件中):

    node: {
   fs: "empty"
}

I also see this thread: https://github.com/webpack/webpack/issues/3012 我也看到此线程: https : //github.com/webpack/webpack/issues/3012

In my code I don't see any "target: "electron", where do I have to put it for a test? 在我的代码中,我没有看到任何“目标:“电子”,我必须在哪里进行测试?

Did you try to add a code like below in your Webpack.config? 您是否尝试在Webpack.config中添加以下代码?

node: {
   fs: "empty"
}

If not, you can have a try and check whether it makes any difference or not. 如果没有,您可以尝试检查一下是否有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM