我正开始使用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
在我的代码中,我没有看到任何“目标:“电子”,我必须在哪里进行测试?
答案 0 :(得分:0)
您是否尝试在Webpack.config中添加如下代码?
node: {
fs: "empty"
}
如果没有,您可以尝试检查一下是否有任何作用。