Electron-packager - The "path" argument must be of type string. Received type undefined
Asked Answered
S

1

7

I have been struggling with this issue and could not figure it out. Similar problems were posted which solutions suggested node version had a glitch or package versions should be down/upgraded. I have tried it with modifying the node versions, reverifying the npm cache and many other fiddles, none worked for me. (it happens during running the app-> electron)

Uncaught Exception: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined at assertPath (path.js:39:11) at basename (path.js:1299:5) at 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) at dispatchUploadFileMessageFromArgs (/Users/ben.izadi/Documents/Developer/gsa-cloud-portal/ui/electron_app/publishTest2-mas-x64/publishTest2.app/Contents/Resources/app/index.js:38:4) at 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) at WebContents.emit (events.js:182:13)

inside my 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"
  }
}
Scandium answered 11/12, 2018 at 23:30 Comment(2)
Could you please give more detail? You get this error when packaging or run app in dev?Gasholder
+upvote i'm having this issue as well and I didn't found a solution yetStites
L
0

You need to set the 'name' that will be used when users type --help

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

Otherwise, this codepath will fail when trying to parse args https://github.com/tj/commander.js/blob/master/index.js#L446

I'm assuming this is Electron specific only, when trying to run the bundled app

Leaflet answered 1/10, 2019 at 7:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.