2

我对电子有问题。

TypeError:无法读取未定义的属性“whenReady”

我使用节点 14.0.1 电子 10.1.2

我运行我的应用程序“电子:服务”:“vue-cli-服务电子:服务”,

我的背景.js

const { app, BrowserWindow } = require('electron')
const { server } = require('feature-server-core')

server.start();

function createWindow () {
    // Создаем окно браузера.

    const win = new BrowserWindow({
        width: 1400,
        height: 900,
        minWidth: 1280,
        minHeight: 800,
        closable: true,
        center: true,
        type: "tool",
        titleBarStyle: "hidden",
    })

    win.menuBarVisible = false;
// и загружаем index.html в приложении.
    win.loadURL("google.com")
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', function () {
        // 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 (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

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

4 回答 4

5

这是与直接调用'index.js'with 节点相关的问题node index.js。您需要使用electron index.jselectron .(如果您的文件是index.js)电子正在构建您的应用程序。

于 2021-02-15T16:21:12.863 回答
3

我解决了同样的问题,只需在文件夹的终端中输入

npm start
于 2020-09-25T14:18:29.677 回答
0

您可以使用npm start而不是node .执行您的应用程序。如果您使用的是 IDE,则必须npm使用该start选项进行配置。

于 2021-03-26T11:37:28.920 回答
0

我有同样的症状,但根本问题与你在互联网上其他地方发现的完全不同。通常,此问题来自意外运行main.jsnode不是electron. 但在我的情况下,问题是在项目文件夹和一些子文件夹上设置了 NTFS 区分大小写标志,因为它们最初是使用 WSL 创建的。这会导致奇怪的事情,比如electron.cmd由于 Windows 寻找electron.CMD带有大写扩展名等原因而找不到,并且显然 Electron 本身内部也存在一些类似的问题,这使得它认为我们毕竟不在 Electron 内部,给了我们 non-Electronelectron没有的版本app

解决方案是使用 Windows 资源管理器创建整个项目文件夹的副本,并使用该文件夹而不是原始文件夹。Windows 资源管理器不保留区分大小写标志,因此创建文件夹的副本也会清除所有子文件夹中的标志。(然后您可以删除旧文件夹。)

有关 NTFS 中区分大小写的更多信息:https ://www.howtogeek.com/354220/how-to-enable-case-sensitive-folders-on-windows-10/


另一个原因可能是设置了环境变量ELECTRON_RUN_AS_NODE=1,可能是很久以前的一些实验或测试。确保未设置此变量。

于 2021-01-02T11:08:56.833 回答