#electron packaged app arguments coming through to the module loader and fail

45 messages · Page 1 of 1 (latest)

winged marten
#

I have an app that runs fine if I run it interactively via cmd.exe, when spawned from another program it takes the first argument I pass to the packaged application and tries to resolve it in the source root folder and the first arg is attempted to be resolved.

internal/modules/cjs/loader.js:801
    throw err;
    ^

Error: Cannot find module 'c:\w\efa\http:\google.com'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:798:15)
    at Module._load (internal/modules/cjs/loader.js:691:27)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1038:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
pallid ice
#

strange module

winged marten
#
Command-line arguments: [
  'c:\\w\\efa\\node_modules\\electron\\dist\\electron.exe',
  'c:\\w\\efa\\src\\index.js'
]
c:\w\efa\src\index.js:26
const userDataPath = app.getPath('userData');
                         ^

TypeError: Cannot read properties of undefined (reading 'getPath')
    at Object.<anonymous> (c:\w\efa\src\index.js:26:26)
    at Module._compile (node:internal/modules/cjs/loader:1271:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
    at Module.load (node:internal/modules/cjs/loader:1126:32)
    at Module._load (node:internal/modules/cjs/loader:967:12)
    at c._load (node:electron/js2c/node_init:2:13672)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:101:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.18.2
#

i've tried passing -- before the arguments. that doesn't help.

winged marten
pallid ice
#

With require?

#

I don't think its correct way

winged marten
#

i don't understand with require. I used const { app, BrowserWindow, globalShortcut,screen } = require('electron');
is that the require you're refering to?

pallid ice
#
internal/modules/cjs/loader.js:801
    throw err;
    ^

Error: Cannot find module 'c:\w\efa\http:\google.com'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:798:15)
    at Module._load (internal/modules/cjs/loader.js:691:27)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1038:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
#

second error means js file is not executed by electron

#

or app in undefined

#

packaged app doesnt use c:\\w\\efa\\node_modules\\electron\\dist\\electron.exe

#

packaged app use its own executable

winged marten
#

yes, I understand that and that's what I'm using

#

if I run using npm run start from the app source root, it does work. using the executable does not work and leads to it trying to resolve the arguments passed

pallid ice
#

have you build your app?

winged marten
#

yes to make the app, I use electron-force and npm run make and package work find and produce a exe

pallid ice
#

show folder with exe

winged marten
#
02/05/2024  10:56 AM       104,074,752 chrome-frameless-app.exe
02/05/2024  10:54 AM           179,633 chrome_100_percent.pak
02/05/2024  10:54 AM           319,769 chrome_200_percent.pak
02/05/2024  10:54 AM         4,481,992 d3dcompiler_47.dll
02/05/2024  10:54 AM         2,338,304 ffmpeg.dll
02/05/2024  10:54 AM        10,505,952 icudtl.dat
02/05/2024  10:54 AM           376,320 libEGL.dll
02/05/2024  10:54 AM         7,947,776 libGLESv2.dll
02/05/2024  10:54 AM             1,060 LICENSE
02/05/2024  10:54 AM         4,772,714 LICENSES.chromium.html
02/05/2024  10:56 AM    <DIR>          locales
02/05/2024  10:56 AM    <DIR>          resources
02/05/2024  10:54 AM         9,302,547 resources.pak
02/05/2024  10:54 AM           225,272 snapshot_blob.bin
02/05/2024  10:56 AM    <DIR>          swiftshader
02/05/2024  10:54 AM           622,528 v8_context_snapshot.bin
02/05/2024  10:54 AM                 5 version
02/05/2024  10:54 AM        16,626,176 vk_swiftshader.dll
02/05/2024  10:54 AM               106 vk_swiftshader_icd.json```
pallid ice
#

chrome-frameless-app.exe ?

#

run chrome-frameless-app.exe from terminal and show output

#

with screenshot

winged marten
#

I can't deep dive right now.

c:\w\efa\out\chrome-frameless-app-win32-x64>chrome-frameless-app.exe http://google.com

c:\w\efa\out\chrome-frameless-app-win32-x64>
Command-line arguments: [
  'c:\\w\\efa\\out\\chrome-frameless-app-win32-x64\\chrome-frameless-app.exe',
  'http://google.com'
]
userDataPath C:\Users\dhorner\AppData\Roaming\chrome-frameless-app
Command-line arguments: [
  'c:\\w\\efa\\out\\chrome-frameless-app-win32-x64\\chrome-frameless-app.exe',
  'http://google.com'
]
opt: {
  x: 0,
  y: 0,
  width: 800,
  height: 600,
  frame: false,
  alwaysOnTop: true,
  webPreferences: { nodeIntegration: false }
}
(electron) The default value of app.allowRendererProcessReuse is deprecated, it is currently "false".  It will change to be "true" in Electron 9.  For more information please check https://github.com/electron/electron/issues/18397
url:
main URL argument:
#

I can get a repo together to share the code.

pallid ice
#

your code is runned

#

and i dont see errors from above

winged marten
#

ya when spawned from another process it does what it does.

pallid ice
#

then problem with another process

#

not with electron

winged marten
#

Failed to compile C:/w/efa/out/chrome-frameless-app-win32-x64/resources/app/src/index.html: Asked for C:/w/efa/out/chrome-frameless-app-win32-x64/resources/app/src/index.html but it was not precompiled!

#

that is what happens when run from the above.

#

it doesn't get the url argument I passed it and tried to load the local file which gives this error.

pallid ice
#

output show opposite

winged marten
#

sthat is what was the orginal post shows.

#

I have to get back to something and can't tease the error into a sample. i will come back to this. thank you for trying to help!

pallid ice
#

and such electron version is outdated

winged marten
#

i tried to npm install latest.

pallid ice
#

if you trying to open url in dev you need to pass js file and url

#

electron <js file> url

#

and you receive 3 args

#

in production only 2

#

with forge its npm run start -- <url>

#

with space

winged marten
#

ya I figured that out and added the -- to the start in package.json

winged marten
#

npm run start -- -- --url= works for me after recreating the app using npm init electron-app@latest my-app