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
If have an app whose main process is implemented as ES modules, and when I add a native dependency and don't merge the ASARs, the app fails to run with:
Uncaught Exception:
Error [ERR_REQUIRE_ESM]: require() of ES Module /private/var/folders/x5/lg2888612qx6k46g8t0b3llm0000gn/T/AppTranslocation/012E8191-C14B-424C-A98A-B6E43D98B159/d/Rowan Patents.app/Contents/Resources/app-arm64.asar/src/index.mjs not supported.
Instead change the require of /private/var/folders/x5/lg2888612qx6k46g8t0b3llm0000gn/T/AppTranslocation/012E8191-C14B-424C-A98A-B6E43D98B159/d/Rowan Patents.app/Contents/Resources/app-arm64.asar/src/index.mjs to a dynamic import() which is available in all CommonJS modules.
at l._load (node:electron/js2c/asar_bundle:2:13642)
at Object.<anonymous> (/private/var/folders/x5/lg2888612qx6k46g8t0b3llm0000gn/T/AppTranslocation/012E8191-C14B-424C-A98A-B6E43D98B159/d/Rowan Patents.app/Contents/Resources/app.asar/index.js:27:1)
at l._load (node:electron/js2c/asar_bundle:2:13642)
at node:electron/js2c/browser_init:2:120247
at node:electron/js2c/browser_init:2:120456
at node:electron/js2c/browser_init:2:120460
at l._load (node:electron/js2c/asar_bundle:2:13642)
I have worked around it using patch-package and replacing has-asar.js with a has-asar.mjs that looks like
import{app}from'electron';importpathfrom'path';if(process.arch==='arm64'){setPaths('arm64');}else{setPaths('x64');}functionsetPaths(platform){// This should return the full path, ending in something like// Notion.app/Contents/Resources/app.asarconstappPath=app.getAppPath();constasarFile=`app-${platform}.asar`;// Maybe we'll handle this in Electron one dayif(path.basename(appPath)==='app.asar'){constplatformAppPath=path.join(path.dirname(appPath),asarFile);// This is an undocumented API. It exists.app.setAppPath(platformAppPath);}process._archPath=`../${asarFile}`;}awaitimport(`${process._archPath}/src/index.mjs`);
However, I'm not sure how to turn this into a general purpose solution because:
I hard-coded the path to my application's entry point (src/index.mjs) and I'm not sure a good way to determine it dynamically.
I'm not sure what process._archPath should actually be in this case?
The text was updated successfully, but these errors were encountered:
Hey @bendemboski, I was taking a look at this today and it seems like the repro case happens whenever the x64 and arm64 ASARs diverge.
Converting the asar.js shim into its ESM equivalent indeed seems to fix the problem on my end.
Don't have time to put up a PR today but this seems to work according to my local testing.
// has-asar.mtsimport{app}from'electron';import{createRequire}from'node:module';importpathfrom'node:path';if(process.arch==='arm64'){awaitsetPaths('arm64');}else{awaitsetPaths('x64');}asyncfunctionsetPaths(platform: string){// This should return the full path, ending in something like// Notion.app/Contents/Resources/app.asarconstappPath=app.getAppPath();constasarFile=`app-${platform}.asar`;// Maybe we'll handle this in Electron one dayif(path.basename(appPath)==='app.asar'){constplatformAppPath=path.join(path.dirname(appPath),asarFile);// This is an undocumented API. It exists.app.setAppPath(platformAppPath);}constrequire=createRequire(import.meta.url);process._archPath=require.resolve(`../${asarFile}`);awaitimport(process._archPath);}
If have an app whose main process is implemented as ES modules, and when I add a native dependency and don't merge the ASARs, the app fails to run with:
I have worked around it using
patch-package
and replacinghas-asar.js
with ahas-asar.mjs
that looks likeHowever, I'm not sure how to turn this into a general purpose solution because:
src/index.mjs
) and I'm not sure a good way to determine it dynamically.process._archPath
should actually be in this case?The text was updated successfully, but these errors were encountered: