Electron-packager-“ path”自变量必须为字符串类型。接收类型未定义

时间:2018-12-11 23:30:28

标签: node.js electron electron-builder electron-packager

我一直在努力解决这个问题,无法解决。张贴了类似的问题,这些解决方案表明节点版本有故障,或者应该降级/升级软件包版本。我尝试过修改节点版本,重新验证npm缓存和许多其他小提琴,但没有一个对我有用。 (发生在运行app->电子的过程中)

  

未捕获的异常:   TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须为字符串类型。接收类型未定义       在assertPath(path.js:39:11)       在基本名称下(path.js:1299:5)       在Command.parse(/Users/ben.izadi/Documents/Developer/gsa-cloud-portal/ui/electron_app/publishTest2-mas-x64/publishTest2.app/Contents/Resources/app/node_modules/commander/index.js中: 462:30)       在dispatchUploadFileMessageFromArgs(/Users/ben.izadi/Documents/Developer/gsa-cloud-portal/ui/electron_app/publishTest2-mas-x64/publishTest2.app/Contents/Resources/app/index.js:38:4)中       在WebContents.win.webContents.on(/Users/ben.izadi/Documents/Developer/gsa-cloud-portal/ui/electron_app/publishTest2-mas-x64/publishTest2.app/Contents/Resources/app/index.js中: 11:5)       在WebContents.emit(events.js:182:13)

在我的index.js中:

const { app, BrowserWindow } = require('electron')
var program = require('commander');
path = require('path');

var win = null;

function createWindow() {
  win = new BrowserWindow({ width: 1024, height: 768 })
  win.loadFile('./app/index.html');
  win.webContents.on('did-finish-load', () => {
    dispatchUploadFileMessageFromArgs(process.argv);
  })
}

const instanceLock = app.requestSingleInstanceLock();
if (!instanceLock) {
  app.quit()
} else {
  app.on('second-instance', (event, argv, workingDirectory) => {
    if (win) {
      if (win.isMinimized()) {
        win.restore();
      }
      win.focus();
      dispatchUploadFileMessageFromArgs(argv);
    }
  })

  app.on('ready', createWindow);
}

function dispatchUploadFileMessageFromArgs(argv) {
  program
  .option(
    "-m, --modelfile [modelfile]",
    "Model to analyse in the GSA Cloud Platform"
  )
  .parse(argv);

  if (program.modelfile) {
    var absolutePath = path.resolve(program.modelfile);
    var basename = path.basename(absolutePath);
    win.webContents.send("upload-model-file", basename + "," + absolutePath);
  }
}

Package.json:

{
  "name": "gsa-portal-electron",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron .",
    "start:withfile": "electron . --modelfile ./stairs.gwb",
    "test": "run-script-os",
    "test:win32": "cd node_modules\\mocha\\bin & mocha ..\\..\\..\\tests\\without_upload\\*.spec.js",
    "test:darwin:linux": "./node_modules/mocha/bin/mocha tests/without_upload/*.spec.js",
    "test:ci": "xvfb-maybe ./node_modules/mocha/bin/mocha tests/without_upload/*.spec.js",
    "testupload": "run-script-os",
    "testupload:win32": "cd node_modules\\mocha\\bin & mocha ..\\..\\..\\tests\\upload\\*.spec.js",
    "testupload:darwin:linux": "./node_modules/mocha/bin/mocha tests/upload/*.spec.js",
    "testupload:ci": "xvfb-maybe ./node_modules/mocha/bin/mocha tests/upload/*.spec.js"

  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "electron": "^3.0.10",
    "electron-reload": "^1.3.0",
    "mocha": "^5.2.0",
    "run-script-os": "^1.0.3",
    "spectron": "^5.0.0"
  },
  "dependencies": {
    "commander": "^2.19.0"
  }
}

1 个答案:

答案 0 :(得分:0)

您需要设置用户输入--help

时将使用的“名称”

https://github.com/tj/commander.js#usage-and-name

否则,当尝试解析args https://github.com/tj/commander.js/blob/master/index.js#L446

时,此代码路径将失败

当我尝试运行捆绑的应用时,我假设这仅是电子特定的