You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like you added support for automatic search for module inside node_modules.asar via addAsarToLookupPaths as in hooking Module._resolveLookupPaths - however not in app.asar which is the default bundle for electron(-builder) given that might also include node_modules.
In my case I'm calling child_process.fork inside an Electron-App for a background-server that I want to require node_modules and dependencies inside app.asar.
Furthermore I'm unsure if your code even properly works - I had to refactor it quite a bit to make it work.
See below example code - if you want I can refine this into a PR to add a configuration option to search in an array-list of files so that your current addAsarToLookupPaths can be replaced by a more generic utility for all cases.
Do you want a PR? :)
// top of your entryPoint.js or whatever module that you want to forkconstasar=require('asar-node');constpath=require('path');constModule=require('module');asar.register();constbaseDir=path.join(__dirname,"../");const_orgResolveLookupPaths=Module._resolveLookupPaths;(functionhookModule(){if(Module.isHooked)return;functionappendPaths(request,paths){let_possibleAppendedPaths=[path.join(baseDir,"/app.asar/","/node_modules/",request)];for(leti=0;i<paths.length;i++){const_path=paths[i];constisBaseDir=_path.indexOf(baseDir);if(isBaseDir>-1&&_path.indexOf("app.asar")<0){_possibleAppendedPaths.push(path.join(baseDir,"/app.asar/",_path.substr(isBaseDir+baseDir.length)))}}returnpaths=paths.concat(_possibleAppendedPaths);}Module._resolveLookupPaths=function(request,parent){if(parent&&parent.paths){parent.paths=appendPaths(request,parent.paths);}return_orgResolveLookupPaths.call(this,request,parent)}Module.isHooked=true})();//----- your regular dependencies afterwardsconstexpress=require('express');//will be loaded from ./app.asar/node_modules/express successfully
The text was updated successfully, but these errors were encountered:
It seems like you added support for automatic search for module inside node_modules.asar via addAsarToLookupPaths as in hooking Module._resolveLookupPaths - however not in app.asar which is the default bundle for electron(-builder) given that might also include node_modules.
In my case I'm calling child_process.fork inside an Electron-App for a background-server that I want to require node_modules and dependencies inside app.asar.
Furthermore I'm unsure if your code even properly works - I had to refactor it quite a bit to make it work.
See below example code - if you want I can refine this into a PR to add a configuration option to search in an array-list of files so that your current addAsarToLookupPaths can be replaced by a more generic utility for all cases.
Do you want a PR? :)
The text was updated successfully, but these errors were encountered: