Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packing heapdump using *pkg* in a Node.js executable on Windows #115

Open
gschmottlach-xse opened this issue Mar 20, 2018 · 4 comments
Open
Labels

Comments

@gschmottlach-xse
Copy link

I use pkg to package my Node.js application into a single binary executable on Windows. Included in my application (as a package.json dependency) is heapdump. Unfortunately, when packaged with pkg the resulting binary will not run and results in an

Error: Invalid access to memory location.

I traced this down to the fact heapdump is compiled with

'win_delay_load_hook': 'false'

set in the binding.gyp file. This means the addon is expected to be run via an executable named either node.exe or iojs.exe. Unfortunately, the output name of my pkg executable is not one of those two names. As a result, since the heapdump addon has dependencies on exported V8 classes, it will not resolve the symbols it needs and crashes with the (above) error. If I rename my application's *.exe file to node.exe then the heapdump module loads correctly and the application runs as expected.

So, my issue is I want to include heapdump with my binary executable but I cannot name it node.exe. I tried enabling 'win_delay_hook': 'true' which should allow me to name my application whatever I want but the Window's linker complains with the following:

LINK : fatal error LNK1194: cannot delay-load 'node.exe' due to import of data symbol '"__declspec(dllimport) const v8::OutputStream::`vftable'" (__imp_??_7Ou tputStream@v8@@6B@)'; link without /DELAYLOAD:node.exe

This appears to do with the fact that the C++ classes that V8 exports (and heapdump uses) have virtual methods. This issue seems to have been brought up here but it's not clear if there is a work-around that is available.

So, I am looking for a work-around or mechanism that will allow me to package heapdump with my application without forcing me to rename my entire application node.exe. Can anyone offer a suggestion that allows heapdump to be packaged with pkg as a single executable?

@bnoordhuis
Copy link
Owner

Perhaps not exactly what you're asking for but newer Node.js versions give you programmatic access to the heap profiler through the inspector API.

It's the HeapProfiler.takeHeapSnapshot RPC method, you call it with session.post().

@gschmottlach-xse
Copy link
Author

Thanks for the tip, but unfortunately I can't move to Node 10.x yet due to constraints in other packages I need.

@den4md
Copy link

den4md commented Jun 30, 2022

I had a similar situation (tried to make Win executable with pkg@4.3.7 including heapdump module), but I had different output:

pkg/prelude/bootstrap.js:1178
      throw error;
      ^

Error: Module did not self-register.
    at Object.Module._extensions..node (module.js:662:18)
    at Module.load (module.js:552:32)
    at tryModuleLoad (module.js:495:12)
    at Function.Module._load (module.js:487:3)
    at Module.require (module.js:577:17)
    at Module.require (pkg/prelude/bootstrap.js:1159:31)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\snapshot\hello-world\node_modules\heapdump\index.js:16:15)
    at Module._compile (pkg/prelude/bootstrap.js:1254:22)
    at Object.Module._extensions..js (module.js:644:10)
    at Module.load (module.js:552:32)
    at tryModuleLoad (module.js:495:12)
    at Function.Module._load (module.js:487:3)
    at Module.require (module.js:577:17)
    at Module.require (pkg/prelude/bootstrap.js:1159:31)

The real error (wrong executable's name) was disguised as error with wrong written addon.
Maybe it's because my specific node version:

{ http_parser: '2.7.0',                                
  node: '8.9.0',       
  v8: '6.1.534.46',    
  uv: '1.15.0',        
  zlib: '1.2.11',      
  ares: '1.10.1-DEV',  
  modules: '57',       
  nghttp2: '1.25.0',   
  openssl: '1.0.2l',   
  icu: '59.1',         
  unicode: '9.0',      
  cldr: '31.0.1',      
  tz: '2017b' ,
  node-gyp: '3.6.2'}

It might be worth to pay attention in the relevant section of Caveats for windows.

@liesauer
Copy link

liesauer commented Nov 7, 2023

@den4md same here, and i am facing another cross-platform packing issue. i use pkg to pack both windows and linux executable on my windows machine, and when i run the app on linux, i get this error

pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error: /tmp/pkg/aaaedb0313186ac7c75c74782abae9088bd26c644da503568de1f1eeeb6924c5/heapdump/build/Release/addon.node: invalid ELF header
    at process.dlopen (pkg/prelude/bootstrap.js:2251:28)
    at Module._extensions..node (node:internal/modules/cjs/loader:1196:18)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:834:12)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/snapshot/aaaaa/node_modules/heapdump/index.js:16:15)
    at Module._compile (node:internal/modules/cjs/loader:1112:14)
    at Module._compile (pkg/prelude/bootstrap.js:1933:32) {
  code: 'ERR_DLOPEN_FAILED'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants