簡體   English   中英

electronic-edge-js:無法解析fs和路徑

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

我開始使用angular進行開發,並且想要實現一個帶有electronic和electronic-edge.js的應用程序。

我設置環境沒有問題,並且能夠使電子起作用。

但是,當我到達那一刻我想使用電子邊緣時,我發現停止工作了。

這些是我遇到的錯誤:

*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.*

看來這些錯誤尚未解決,但對某些人來說仍然可以解決。.我已經測試了很多帖子答案中發現的許多修復程序,但似乎沒有任何效果。 我可能會錯過一些東西。

這是我稱為需求的代碼,它會產生問題:

 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();
    }
});

最后是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"
  },``

編輯(基於第一個答案):

我嘗試添加

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

到電子的package.json中。 這解決了第一個問題,但產生了一個新問題:

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)

我認為fs對於電子是必需的,或者不是^^

我必須將代碼放在哪里(在wich文件中):

    node: {
   fs: "empty"
}

我也看到此線程: https : //github.com/webpack/webpack/issues/3012

在我的代碼中,我沒有看到任何“目標:“電子”,我必須在哪里進行測試?

您是否嘗試在Webpack.config中添加以下代碼?

node: {
   fs: "empty"
}

如果沒有,您可以嘗試檢查一下是否有所不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM