gpt4 book ai didi

node.js - ionic 和 Electron 应用程序未启动。启动应用程序时出错,在 {Project Directory} 中找不到模块

转载 作者:行者123 更新时间:2023-12-03 12:35:05 25 4
gpt4 key购买 nike

我一直在尝试将 ionic 应用程序转换为桌面应用程序,但似乎找不到解决方案。每当我运行 electron . ,我得到一个弹出窗口,上面写着
Error launching app

我已将我的主脚本添加到我的 package.json 并添加了一个自定义构建命令,该命令构建我的应用程序并随后运行 Electron 。我的 package.json 看起来像这样

{
"name": "businessapp-desktop",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"electon-serve": "ionic-app-scripts build && electron ."
},
"main":"electron/electron.js",
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "~4.17.0",
"@ionic-native/splash-screen": "~4.17.0",
"@ionic-native/status-bar": "~4.17.0",
"@ionic/pro": "2.0.3",
"@ionic/storage": "2.2.0",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.1",
"electron": "^3.0.10",
"typescript": "~2.6.2"
},
"description": "An Ionic project"
}

还有我的 electron.js看起来像这样
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

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 mainWindow;

function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1200, height: 700});

// and load the index.html of the app.
const startUrl = process.env.ELECTRON_START_URL || url.format({
pathname: path.join(__dirname, '/../www/index.html'),
protocol: 'file:',
slashes: true
});
mainWindow.loadURL(startUrl);
// Open the DevTools.
mainWindow.webContents.openDevTools();

// Emitted when the window is closed.
mainWindow.on('closed', function () {
// 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.
mainWindow = null
})
}

// 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', function () {
// On OS X 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', function () {
// On OS X 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 (mainWindow === null) {
createWindow()
}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

我已经安装了 Electron 依赖项 npm i --save-dev electron但每当我尝试运行 electron .如教程 here 中所述我得到上面的错误。

我将不胜感激提供的任何帮助。

最佳答案

终于修好了。问题是打印的。我的应用程序无法访问 main.js,因为文件路径错误。如果您遇到类似问题,请检查您的文件路径。

关于node.js - ionic 和 Electron 应用程序未启动。启动应用程序时出错,在 {Project Directory} 中找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53666474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com