角/电子不发射 [英] Angular / Electron not launching

查看:37
本文介绍了角/电子不发射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用angular-CLI创建了一个angular 10项目.之后,我已经安装了Electron并完成了此操作:将src/index.html base更改为Localed Installed Electron.但是运行我的代码时,它显示出一些错误.

I have created an angular 10 project using the angular-CLI. Following that that I have installed Electron and done this: changed src/index.html base to Installed Electron locally. but when run my code, it shows have some error.

如何解决此错误?

这是我的 main.js 文件

const { app, BrowserWindow } = require('electron')

let win;

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({
    width: 600, 
    height: 670,
    icon: `file://${__dirname}/dist/assets/logo.png`
  })

  win.loadURL(`file://${__dirname}/dist/index.html`)

  // uncomment below to open the DevTools.
  // win.webContents.openDevTools()

  // Event when the window is closed.
  win.on('closed', function () {
    win = null
  })
}

// Create window on electron intialization
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {

  // On macOS specific close process
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  // macOS specific close process
  if (win === null) {
    createWindow()
  }
})

这是我的 package.json 文件

{
  "name": "angu",
  "version": "0.0.0",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "electron":"electron .",
    "electron-build": "ng build --prod && npm run electron ."
  },

这是我的 index.html 文件

  <base href="./">

推荐答案

在过去的两天里,我也一直陷在这个问题中.并且经过大量的搜索并获得了对电子的理解.我已解决此问题以及此问题之后的问题.

I were also stuck in this problem for last 2 days. And after a lot of searching and getting understanding of electron. I fixed this issue and issues after that issue.

为解决的问题,请验证package.json是否具有有效的"main"(主).肠

您需要使用 main.js 文件的路径更新 package.json 文件中的 main .很有可能是

You need to update your main in package.json file with path of main.js file. Most probably that will be

"main":"src/main.js",

进行此更改时,请运行命令 npm run electro-build .它将创建您的电子应用程序的构建,但不会在页面上显示任何内容,如果您看到控制台,在这里您将看到1错误不允许加载本地资源:.要解决此错误,您应该访问以下链接

When you will do this change, run the command npm run electron-build. It will create the build of your electron app but will not show anything on the page and if you see the console, here you will see the 1 error Not allowed to load local resource: . To solve this error you shoudl visit these following links

电子-不允许加载本地资源

https://github.com/JacopoMangiavacchi/TFRecords/issues/1

这篇关于角/电子不发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆