fix(node): support Electron host on Windows#28
Open
JackCaow wants to merge 1 commit into
Open
Conversation
JackCaow
marked this pull request as ready for review
July 21, 2026 15:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
node.exeand link a Windows host redirection hook into the final Node-API addon;node.exenormally instead of through the delay-import directory;Fixes #27.
Root cause
The published Windows addon links Node/N-API exports through a normal
node.exePE import. This works when the host executable is Node itself, but a renamed Node-API host such as Electron cannot redirect that normal import. On the reported machine Windows loaded an unrelatednode.exefromPATH, and N-API calls entered an uninitialized Node image, causing a process-fatal execute access violation before ONNX Runtime session creation.Linking
node.libis not itself the defect: that import library commonly recordsnode.exeas the symbol provider. The missing piece is the established Windows delay-load hook that redirects the request to an already loadedlibnode.dllor the current process executable.Fix
/DELAYLOAD:node.exeand linkdelayimp;win_delay_load_hook.cpp, resolvinglibnode.dllfirst and otherwiseGetModuleHandleW(nullptr);node.exeimport or a missing delayed import;echoo.exe/electron.exerewrite.Validation
GitHub Actions run: https://github.com/JackCaow/light-ocr/actions/runs/29826497872
Both
windows-x64 contractandlinux-x64 contractpassed for commit8fe3dfedad3f402d9e769e2e5df8aa1f3db234fc.Windows PE gate:
{ "delayImports": ["node.exe"], "normalImports": ["onnxruntime.dll", "KERNEL32.dll", "MSVCP140.dll"] }Windows Electron smoke:
{ "electron": "37.10.0", "node": "22.21.1", "platform": "win32-x64", "requestedProvider": "cpu", "actualProvider": "CPUExecutionProvider", "text": "HELLO 123" }Additional gates passed in the same run:
Compatibility and scope
The hook preserves normal Node support and supports differently named Electron executables without editing the compiled PE per consumer. This PR validates the Windows host-binding contract and an Electron 37 CPU smoke; it does not promote Electron to full Tier 1 support for ASAR, worker, or lifecycle behavior.