我开始用angular开发,我想用electron和electron-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');
}
如果我删除“边缘=需要('electron-edge-js');“一切正常。因此,电子边缘js可能是问题的根源(嗯,我可能是问题的根源)
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
}
到electron的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对于电子是必要的,或者不是。
我必须把下面的代码放在哪里(在哪个文件中?):
node: {
fs: "empty"
}
我还看到了这条线索:https://github.com/webpack/webpack/issues/3012
在我的代码中,我没有看到任何“目标:“电子”,我得把它放在哪里做测试?
1条答案
按热度按时间hc2pp10m1#
您是否尝试在Webpack.config中添加类似下面的代码?
如果没有,你可以试一下,看看是否有什么不同。