电子角:主要过程中发生JavaScript错误

时间:2019-08-24 15:04:23

标签: javascript angular electron

我正在使用电子和角度构建Windows桌面应用程序。该应用程序在开发过程中按预期工作,但是当我生成.exe文件并运行该应用程序时,出现以下错误:

Electron Error

我无法在此处上传图片,这是链接:https://ibb.co/nMFQJnr

我的electron.service.ts文件:

import { Injectable } from '@angular/core';

// If you import a module but never use any of the imported values other than as TypeScript types,
// the resulting javascript file will look as if you never imported the module at all.
import { ipcRenderer, webFrame, remote, PrintOptions } from 'electron';
import * as childProcess from 'child_process';
import * as fs from 'fs';

//Start  Native Module Imports
import * as path from 'path';
import * as os from 'os';
const { BrowserWindow, dialog, shell } = remote;
import * as SerialPort from 'serialport';
//End  Native Modules Imports



@Injectable()
export class ElectronService {


  ipcRenderer: typeof ipcRenderer;
  webFrame: typeof webFrame;
  remote: typeof remote;
  childProcess: typeof childProcess;
  fs: typeof fs;
  path: typeof path;
  os: typeof os;
  serialPort: typeof SerialPort;

  constructor() {

    // Conditional imports
    if (this.isElectron()) {
      this.ipcRenderer = window.require('electron').ipcRenderer;
      this.webFrame = window.require('electron').webFrame;
      this.remote = window.require('electron').remote;

      this.childProcess = window.require('child_process');
      this.fs = window.require('fs');
      this.path = window.require('path');
      this.os = window.require('os');

      this.serialPort = window.require('serialport');


    }
  }

  isElectron = () => {
    return window && window.process && window.process.type;
  }



  //Start Printer Section

  getPrinters() {

    let printWindow = new BrowserWindow({ autoHideMenuBar : true,show:false });
   // printWindow.loadURL("www.google.com");
    let list = printWindow.webContents.getPrinters();
    // console.log("All printer available are ",list);
    return list;
}

onSendTextToPrinter(printerOptions: PrintOptions){
  let printWindow = new BrowserWindow({ autoHideMenuBar : true,show:false });
  printWindow.webContents.print(printerOptions, (success)=>{
      console.log(success);
  });

}

onSendTextToPrinterPrintPDF(){
  let printWindow = new BrowserWindow({ autoHideMenuBar : true,show:false });
  console.log("Electron Service before pdfePath");
  const pdfPath = this.path.join(this.os.tmpdir(), 'print.pdf');

  console.log("Electron Service After pdfePath");
  printWindow.webContents.printToPDF({}, function(error, data){
console.log("My Data: "+ data );
console.log("My Error: "+ error);
    if(error) throw error;


    fs.writeFile(pdfPath, data, function(error){
      if(error) throw error;

      shell.openItem(pdfPath);

    });



  });

}
  //End Printer Section


  }

我的main.ts文件

import { app, BrowserWindow, screen, ipcMain } from 'electron';
import * as path from 'path';
import * as url from 'url';

import { createConnection, getConnection } from 'typeorm';
import { User } from './typeormmodels/user.model';


let win, serve;
const args = process.argv.slice(1);
serve = args.some(val => val === '--serve');

let fileName = 'database.sqlite3';
let dbpat = `${process.env.NODE_ENV === 'dev' ? `./typeormmodels/data/${fileName}` : app.getPath('userData')}/data/${fileName}`;

async function createWindow() {


  //START CUSTOM FUNCTION
  //Start Initiate Database Connection
  const connection = await createConnection({
    type: 'sqlite',
    synchronize: true,
    logging: true,
    logger: 'simple-console',
    database: `${dbpat}`, 
    entities: [User],
  });

  const userRepo = connection.getRepository(User);

0 个答案:

没有答案