简体   繁体   中英

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.

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:

 {"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. 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 ^^

Where do I have to put the code below (in wich file ?):

    node: {
   fs: "empty"
}

I also see this thread: 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?

node: {
   fs: "empty"
}

If not, you can have a try and check whether it makes any difference or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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