#Invalid filename app.asar\node_modules, why? how can i fix it?

279 messages · Page 1 of 1 (latest)

dark jackal
#

I'm using a package when i try to create a new instance new something() i got this error

Error: Invalid filename
    app.asar\node_modules\adm-zip\adm-zip.js:57:19)
    app.asar\node_modules\generative-bayesian-network\bayesian-network.js:24:21)
   ... (and so on)

I check this page, https://www.electronjs.org/docs/latest/tutorial/asar-archives , i can see some similarities but I don't understand how it works, can someone explain and help me?

What is ASAR archive and how does it affect the application.

cerulean minnow
#

"I'm using a package"

#

ya mean ADM-ZIP?

#

how is this related to ASAR?

#

If you get this error you're doing something wrong with the library, read its doc

dark jackal
#

this triggers the error
new FingerprintGenerator()

#

from this
import { FingerprintGenerator } from 'fingerprint-generator'

#

any idea @cerulean minnow ?

cerulean minnow
#

I can google it for you......

#

you should make you own research before asking for help :/

dark jackal
#

I'm really sorry, I was focus on doc 😦 MB, thank you very much 🙏

cerulean minnow
#

GitHub issues is a great place to find all sort of things

dark jackal
#

I'm not used to search there tbh, I need to get that habbit ... btw, they show the issue but not the solution right? i need to edit the package inside node to make it work or there aren't any solution? I'm leaving home so i can't test right now xO

cerulean minnow
#

I never used this package, I have not idea how it works, but you can probably get a hint by looking at the error, and find out if it's an actual bug, or you who missed something

#

see the part of ADM-ZIP that throws the error

#

how do you understand it?

#
module.exports = function (/**String*/ input, /** object */ options) {

[...]

 // if input is file name we retrieve its content
 if (input && "string" === typeof input) {
  // load zip file
  if (filetools.fs.existsSync(input)) {
    opts.method = Utils.Constants.FILE;
    opts.filename = input;
    inBuffer = filetools.fs.readFileSync(input);
  } else {
    throw new Error(Utils.Errors.INVALID_FILENAME);
  }
}
#

So, what could be the reason for the error to be thrown?

#

I want you to do the job of debugging

dark jackal
#

Driving 5min

#

I want you to guide me, not giving the solution, so I learn 😁

cerulean minnow
#

I'm fine with that 🙂

#

and I don't know the solution anyway, but that how I would proceed

dark jackal
#

I'm not back, so I will take some time to reply
Well we can see the "invalid file name error" there so the problem is on the filetools.fs.existsSync right?

cerulean minnow
#

not really a problem

#

it does its job

#

you want it to go to the if, but it goes to the else, why?

dark jackal
#

Because the filetool fs is trying to check if file exist ? And probably its targeting the wrong path ? Dunno 😔

cerulean minnow
#

wrong path, or correct path but the file is missing

#

ADMZip is a good library but the errors thrown often lack of details, the actual error you should get is "[input] doesn't exist"

#

So now you know ADM is trying to get a .zip file but can't find it

#

now the question is: what file?

#

go back to the error stack and check what is calling ADM

dark jackal
#

Hmmmm why it works on dev and not prod ? Because in Dev it's not ASAR ?
I will try to connect to my pc to copy past the error stack

cerulean minnow
#

the part you shared is enough

#

someone already did the debugging so you actually don't need to repeat the whole process, but you should find that yourself if you do the next step correctly

#

I think you are on the correct path though

dark jackal
#

I would say Adm-zip.js because it's the first error line, but if it is I have no clue why, can you explain to me ?

#

So the admn-zip.js is looking for a file .zip is that ?

cerulean minnow
#
Error: Invalid filename
    app.asar\node_modules\adm-zip\adm-zip.js:57:19)
    app.asar\node_modules\generative-bayesian-network\bayesian-network.js:24:21)
   ... (and so on)

The first line indeed tells you the error comes from adm-zip, line 57 character 19
the second line tell you what file is calling adm-zip, and on what line
the next tell you what file call the file calling adm-zip and so on

cerulean minnow
dark jackal
#

Ok, I will try to check on my phone and come back to discuss with you
Thank you @cerulean minnow

dark jackal
#

I need a small help or guide, I'm feeling lost, don't even know what am I looking for again ...

#

String === typeof input

#

That one right ?

cerulean minnow
#

of you still there

#

we already figured out why ADM why throwing an error

dark jackal
#

I'm multitasking right now 🤣
Doing the laundry 🧺 haha

cerulean minnow
#

What we are doing is the hard way so you understand, but if you want, you can actually find an explanation on this error by searching in the github issues of the library you use

#

the issue I gave you is specific for Electron, but there is another one

dark jackal
#

No, I would like to understand 😁
I will do another search ... I want to understand on the electron side, because I never had issues with the lib (I just migrated my project from node/normal js to electron, and I'm having some issues , that one and cluster one (I will investigate and solve that one later)

#

Input is the file name and existsync check if it's exist otherwise gives an error

cerulean minnow
#

yes

dark jackal
#

That's my best approach, or you were expecting a different answer ?

cerulean minnow
#

no it's correct, you get the error because the file is not found, you can also guess that the file is supposed to be a zip archive, since it's what ADM reads and expects

#

Here is an example from ADM docs:

dark jackal
#

Correct
And the file doesn't exist because the code can't write on that path, is that ?

cerulean minnow
#

I'm not sure to understand what you mean?

dark jackal
#

Nevermind , what I said it was all wrong

cerulean minnow
#

x)

dark jackal
#

But why the file it's not found ?

cerulean minnow
#

that's a good question

#

but I would first wonder what is this file and where it's supposed to be?

dark jackal
#

That's the error question haha 😁
Like I said, in run Dev it works when I build it looks like the file is missing

cerulean minnow
#

so it means something is different between the files you have in dev and the files you have in prod

#

wanna do the whole debugging process using the error stack or try to solve the issue using existing GitHub issues on the subject?

dark jackal
#

If you got time yes ... But I would prefer to do it in front of my computer instead of my phone ... For that I need like 20min xO

#

Any one that you think it's the best to learn

#

One it's more global and the other one it's specific from electron

cerulean minnow
#

Hmm, I think it's important to know how to debug because sometimes you don't have the chance that someone already had the same problem as you and if you don't know how to debug yourself you end up stuck. This is also useful if you need to create a ticket/issue on a repo.

#

But it takes more time too, and in the end you're not even sure you can fix the bug

#

now I think the two existing issues already give enough data to try to solve your problem

dark jackal
#

Perfect ❤️
As soon as I get home I @you here
Brb

dark jackal
#

back you there @cerulean minnow ?

cerulean minnow
#

ya

dark jackal
#

so, lets go fix this issue! 😄
were are we and whats the next step?

#

this is the full error:

Error: Invalid filename
    app.asar\node_modules\adm-zip\adm-zip.js:57:19)
    app.asar\node_modules\generative-bayesian-network\bayesian-network.js:24:21)
    app.asar\node_modules\header-generator\header-generator.js:103:38)
    app.asar\node_modules\fingerprint-generator\fingerprint-generator.js:15:9)
    app.asar\out\main\index.js:520:40)
    app.asar\out\main\index.js:1600:21)
    app.asar\out\main\index.js:1581:11)
cerulean minnow
#

depends on how you want to proceed ^^

dark jackal
#

wanna do the whole debugging process using the error stack
can we?

cerulean minnow
#

okay

#

so we already found what's wrong with the first line, but we don't know what is the missing zip

glad bane
#

Find error in module repo

#

I am pretty sure it's fail on .asar check

cerulean minnow
#

yeah yeah we are doing that step by step Timosh

dark jackal
#

Hi Timosh 🙂

cerulean minnow
#

you're good at debugging too

glad bane
#

Hi

cerulean minnow
#

So Ussa, do you understand which module calls adm?

dark jackal
#

not sure, bayesian-network.js?

#

*generative-bayesian-network

cerulean minnow
#

yes

#

find the repo of this module to find this file

#

it's actually a compiled file, the original is a .ts

cerulean minnow
#

nice

#

do you see where ADM is initialized?

dark jackal
#

line 15? const zip = new AdmZip(path);

cerulean minnow
#

yes, there is also another one below but it doesn't pass a path so it's probably this first one

#

sadly we still don't know what the value of path is

dark jackal
#

right :/

cerulean minnow
#

so we have to continue in the error stack to see how BayesianNetwork is called

dark jackal
#

module header-generator file header-generator.js correct?

cerulean minnow
#

yep

dark jackal
cerulean minnow
#

you faster than me x)

dark jackal
#

input-network-definition.zip
hmmm zip file! 😛

cerulean minnow
#

yeas we can see two of them

dark jackal
#

yup, same path different files

cerulean minnow
#

yep, the what is the full path

#

__dirname is the parent directory of these files

#

and these files are in your node_modules

dark jackal
#

what does that mean? the problem is here? no need to go deeper on error stack rigth? we found the .zip(s) path(s)

cerulean minnow
#

I don't think you need to go deeper since now you know what are the missing files

#

if I'm not wrong, you should have these two zip somewhere in your node_modules

dark jackal
#

the __dirname is the path from the source to the file where __dirname is right?

cerulean minnow
#

it's the path of the parent directory of the file where is this code

dark jackal
cerulean minnow
#

you see the zips?

dark jackal
#

i have both files there

cerulean minnow
#

nice

#

that's why it works in dev

dark jackal
cerulean minnow
#

and I bet the files are missing in your packaged app

dark jackal
#

i also bet that! any way to check?

#

or not worth?

cerulean minnow
#

maybe it's better to check, because the first issue we found says ADM can't read from asar

#

what packager do you use?

dark jackal
cerulean minnow
#

to package your app for prod

#

forge, builder, packager?

dark jackal
#
"build:win": "npm run build && electron-builder --win --config",
cerulean minnow
#

builder okay

dark jackal
#

i'm new at electron, so i try to use the most basic as possible

cerulean minnow
#

so to see what's packaged you can temporarily disable asar

#

asar: false

dark jackal
#

is forge better? i saw that one, didn't read about it yet

cerulean minnow
#

It's a matter of opinion

#

I prefer builder, but Forge is official

dark jackal
cerulean minnow
#

in your builder config

dark jackal
#

electron-builder.yml?

cerulean minnow
#

I suppose?

#

what do you have on this file?

dark jackal
#
appId: com.electron.app
productName: electronapp
directories:
  buildResources: build
files:
  - '!**/.vscode/*'
  - '!src/*'
  - '!electron.vite.config.{js,ts,mjs,cjs}'
  - '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
  - '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
asarUnpack:
  - resources/**
win:
  executableName: electronapp
nsis:
  artifactName: ${name}-${version}-setup.${ext}
  shortcutName: ${productName}
  uninstallDisplayName: ${productName}
  createDesktopShortcut: always
mac:
  entitlementsInherit: build/entitlements.mac.plist
  extendInfo:
    - NSCameraUsageDescription: Application requests access to the device's camera.
    - NSMicrophoneUsageDescription: Application requests access to the device's microphone.
    - NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
    - NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
  notarize: false
dmg:
  artifactName: ${name}-${version}.${ext}
linux:
  target:
    - AppImage
    - snap
    - deb
  maintainer: electronjs.org
  category: Utility
appImage:
  artifactName: ${name}-${version}.${ext}
npmRebuild: false
publish:
  provider: generic
  url: https://example.com/auto-updates
cerulean minnow
#

okay

#

so add asar: false

dark jackal
#

where? anywhere ?

cerulean minnow
#

yes

#

it's not a nested option

dark jackal
#

ok, set at the end, should i build now?

cerulean minnow
#

yes

#

you should have a warning telling you it's bad to have asar disabled

dark jackal
#

hmmm nop 🤣

#

finished

#

everything looks the same O.O (on build path)

cerulean minnow
#

I'm not familiar with yml format

dark jackal
#

what are we expecting and where?

#

i will google it

cerulean minnow
#

maybe you should write asar: False

dark jackal
#

weird the others are false not False let's try

cerulean minnow
#

oh yeah you're right

#

are you sure it's not disabled?

#

if it's disabled you should be able to find your packaged files without an asar archive

dark jackal
#

not sure ... just saw something interesting ...

"FingerprintInjector" is imported from external module "fingerprint-injector" but never used in "src/main/Utility/browser/Browser.js".

cerulean minnow
#

ESLint warning 🙂

dark jackal
#

wrong one

#

xD

cerulean minnow
#

in win-unpacked what do you have?

dark jackal
cerulean minnow
#

in resources?

dark jackal
#

inside app

cerulean minnow
#

right it's good

#

so, now check what's inside node_modules?

dark jackal
#

so i don't need the flag i always have that (for some reason)

cerulean minnow
#

that's super weird

dark jackal
cerulean minnow
#

yes try to see if the zips are here

dark jackal
#

yes they are

cerulean minnow
#

I was not expecting that

#

no asar and the files are here

dark jackal
#

\dist\win-unpacked\resources\app\node_modules\header-generator\data_files

cerulean minnow
#

hmmmmmm

#

still in node_module, can you find the file header-generator\header-generator.js and check what's on line 130?

#

Is supposed to be the path we saw but I want to be sure

dark jackal
#

js or ts? the js it's all converted 😒

cerulean minnow
#

and you sure your app was not in asar before? Have you tried to start it again to see if the error's still here?

cerulean minnow
dark jackal
#

3min

#

dist\win-unpacked\resources\app\node_modules\header-generator\header-generator.js

cerulean minnow
#

huu

#

line 103 sorry xD

dark jackal
#

LOOOL

#
        this.inputGeneratorNetwork = new generative_bayesian_network_1.BayesianNetwork({ path: `${__dirname}/data_files/input-network-definition.zip` });
        this.headerGeneratorNetwork = new generative_bayesian_network_1.BayesianNetwork({ path: `${__dirname}/data_files/header-network-definition.zip` });
cerulean minnow
#

okay so nothing new

#

try to start your app again to be sure?

dark jackal
#

now it work 😐

#

i will remove the asar an try again

cerulean minnow
#

so you probably had asar

dark jackal
#

is that good or bad?

#

i rly need to read about asar more

cerulean minnow
#

well, not good or bad, but I think it means some module must be outside of asar

#

I have no idea how this can work, but builder as an option asarUnpack to move what you want outside of asar archive, it's required for native modules

dark jackal
#

asar: true -> not working
asar: false -> working

cerulean minnow
#

Maybe @glad bane will have better insights on this than me

dark jackal
#

ok, let's wait for Timosh opinion, thank you very much Arkellys 🙂 I learn some new things today 😄

glad bane
#

opinion in what?

cerulean minnow
#

basically, there a two zip files in node_modules

#

which are not found when in asar

glad bane
#

are they exists in asar?

cerulean minnow
#

yep

#

existsSync(input) returns false

#

but the path is correct

#

and the fs used is the one from ADM-ZIP

#

the first issue we found did say it can't read in asar

dark jackal
#

are they exists in asar?
not sure what you mean with that, but with asar: false we can check the modules and the .zip files are there
with asar: true i can't check the modules folder

glad bane
#

original-fs unable to work witn asar

#

thats the point

cerulean minnow
#

hmm hmm yes

dark jackal
#

hmmmm

glad bane
#

if zips are in asar

#

you getting an error

cerulean minnow
#

would it work to put the module with the zip outside of asar with asarUnpack?

#

I'm a bit afraid it will messes up with the paths

glad bane
#

dont think so

cerulean minnow
#

damn

dark jackal
#

let's try that @cerulean minnow ? 😄

cerulean minnow
#

I'm afraid the module is just not compatible

glad bane
#

i dont know the point for zip file to have http headers in it

#

how you used it?

dark jackal
#

well .. and whats the big diff / consern in using asar: false? what does it change?

cerulean minnow
#

size

glad bane
#

its disable asar

#

as a feature

#

instead of having 20000+ files you have only one

dark jackal
glad bane
#

why you use it?

#

scrap?

#

no

#

scrapping is bad

#

always

dark jackal
#

ow, sorry

#

it's all about learning purposes

glad bane
#

i dont think so

#

never seen ppl emulate browser environment for learing purposes

dark jackal
#

as you can see i have question, i'm learning and trying different things

#

how do you learn QA without emulate a browser? 😄

glad bane
#

learn qa?

#

you didnt emulate it

#

you trick website protection

#

by creating fake fingerprint

#

to bypass website protection?

#

to getting data you didnt supposed to get

dark jackal
#

I'm QA on a company where we use Robot Framework, we need to bypass protection to improve security

glad bane
#

how it is related to electron?

dark jackal
#

electron I'm learning like a said before, and using public repos, and testing, atm my electron peject barely works as you can see

glad bane
#

and bypassing protection didnt improve security

dark jackal
#

ok ...
sorry

glad bane
#

its like using cracked game to impose system security

#

or using cracked application

dark jackal
#

well, no, i don't agree with you, going to www.whatever.com/checkprice/231sad3 it's free and everyone have access to it, using cracking games no. that's super no, but i get your point

glad bane
#

how it is related to security?

dark jackal
#

it's not

glad bane
#

if you able to use www.whatever.com/checkprice/231sad3 then use it

#

from browser

#

how it supposed to be

#

if it have open api then use it