Skip to content

fix: ESM legacyMainResolve with asar - #41348

Closed
codebytere wants to merge 3 commits into
mainfrom
legacymainresolvefix
Closed

codebytere wants to merge 3 commits into
mainfrom
legacymainresolvefix

Conversation

@codebytere

@codebytere codebytere commented Feb 14, 2024 •

Copy link
Copy Markdown
Member

Description of Change

Fixes #41241

Refs nodejs/node#48325 via 9c94fd7afb4706c2d2228a455f0874a0370cfe1d- this issue seems to have been caused by a switch to native legacyMainResolve which does not take asar into account. Override it to fix this.

Before

Screenshot 2024-02-17 at 10 59 22 AM

After

Screenshot 2024-02-17 at 10 57 19 AM

Checklist

Release Notes

Notes: Fixed an issue where some dependencies would cause some ESM apps to fail to open.

@codebytere codebytere added the target/29-x-y PR should also be added to the "29-x-y" branch. label Feb 14, 2024
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Feb 14, 2024
@johnlindquist

Copy link
Copy Markdown

THANK YOU!

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was chatting with Keeley about this, we should be putting ASAR into the native method, not duplicating the native method into JS like this, it's quite complex and drift will be an issue


// Copy out the original package.json into a temp directory so
// it can be read.
const tempPackageJSON = archive.copyFileOut(filePath);

@MarshallOfSound MarshallOfSound Feb 17, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was chatting with keeley about this, we shouldn't be copying the file out to a temp folder just to read it. We should do what we do below and read from the asar fd at the offset

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do what we do below and read from the asar fs at the offset

say a bit more? the impl here is picky about files existing at certain paths so i'm not sure we can drop in that approach quite the same 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying out from DMs:

we should patch the native method used to determine if a file exists / read the package json to use asar::Archive

  • Extract the Archive class to a separate source_set
  • Make lib_electron depend on that source_set
  • Make electron_node depend on that source_set
  • Patch the native method to support ASAR

like, copying a file out of the ASAR for every single module load is kinda crazy and gonna be way too slow

We need to just make node itself aware of ASAR instead of patching in a slow drifting JS impl

@codebytere

Copy link
Copy Markdown
Member Author

Superseded by #41367

@codebytere codebytere closed this Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-pr 🌱 PR opened recently target/29-x-y PR should also be added to the "29-x-y" branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Electron 29. "Cannot Find Packages" when targeting ESM

3 participants