bnoordhuis / node-heapdump

Make a dump of the V8 heap for later inspection.
Other
2.49k stars 130 forks source link

i'm getting build errors and not sure where to run the build command. #174

Open laurencefass opened 1 year ago

laurencefass commented 1 year ago

Ive installed the package and the build step is throwing errors:

nest-mono % node-gyp configure build
gyp info it worked if it ends with ok
gyp info using node-gyp@9.4.0
gyp info using node@16.20.0 | darwin | arm64
gyp info find Python using Python version 3.11.3 found at "/opt/homebrew/opt/python@3.11/bin/python3.11"
gyp info spawn /opt/homebrew/opt/python@3.11/bin/python3.11
gyp info spawn args [
gyp info spawn args   '/Users/laurence.fass/.nvm/versions/node/v16.20.0/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/laurence.fass/SSG/nest-mono/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/laurence.fass/.nvm/versions/node/v16.20.0/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/laurence.fass/Library/Caches/node-gyp/16.20.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/laurence.fass/Library/Caches/node-gyp/16.20.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/laurence.fass/.nvm/versions/node/v16.20.0/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/laurence.fass/Library/Caches/node-gyp/16.20.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/laurence.fass/SSG/nest-mono',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp: binding.gyp not found (cwd: /Users/laurence.fass/SSG/nest-mono) while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/laurence.fass/.nvm/versions/node/v16.20.0/lib/node_modules/node-gyp/lib/configure.js:325:16)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Darwin 22.5.0
gyp ERR! command "/Users/laurence.fass/.nvm/versions/node/v16.20.0/bin/node" "/Users/laurence.fass/.nvm/versions/node/v16.20.0/bin/node-gyp" "configure" "build"
gyp ERR! cwd /Users/laurence.fass/SSG/nest-mono
gyp ERR! node -v v16.20.0
gyp ERR! node-gyp -v v9.4.0
gyp ERR! not ok 

where do i run the build command? its not specified in the readme.

environment:

aurence.fass@SSG-2510 nest-mono % node -v v16.20.0 laurence.fass@SSG-2510 nest-mono % npm -v 8.19.4

any help or advice appreciated.

bnoordhuis commented 1 year ago

It looks like you're in the wrong directory. What happens when you simply npm install heapdump? npm should invoke node-gyp automatically, unless you've explicitly turned that off.

laurencefass commented 1 year ago

i haven't knowingly explicitly turned it off. its only come to my attention now.

installation seems to work ok.

nest-mono %  npm i heapdump

added 1 package, and audited 671 packages in 6s

97 packages are looking for funding
  run `npm fund` for details

25 moderate severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

but running an app results in an error:

Test suite failed to run

    Cannot find module './build/Debug/addon' from 'node_modules/heapdump/index.js'

    Require stack:
      node_modules/heapdump/index.js
      apps/myapp/leaktest/createMemoryLeak1.spec.ts

    > 5 | import heapdump from 'heapdump';

running node-gyp configure build from package.json directory results in the OP error.

Ive got node-gyp installed as a global

 npm ls -g
/Users/laurence.fass/.nvm/versions/node/v16.20.0/lib
├── @nestjs/cli@9.5.0
├── corepack@0.17.0
├── node-gyp@9.4.0
├── npm@8.19.4
├── npx@10.2.2
└── nx@16.3.2
bnoordhuis commented 1 year ago

Can you post the output of find node_modules/heapdump?

laurencefass commented 1 year ago
% find node_modules/heapdump

node_modules/heapdump
node_modules/heapdump/LICENSE
node_modules/heapdump/test
node_modules/heapdump/test/test-callback-error.js
node_modules/heapdump/test/test-callback-without-filename.js
node_modules/heapdump/test/test-sigusr2.js
node_modules/heapdump/test/test-callback.js
node_modules/heapdump/binding.gyp
node_modules/heapdump/index.js
node_modules/heapdump/README.md
node_modules/heapdump/package.json
node_modules/heapdump/.clang-format
node_modules/heapdump/build
node_modules/heapdump/build/gyp-mac-tool
node_modules/heapdump/build/Makefile
node_modules/heapdump/build/Release
node_modules/heapdump/build/Release/addon.node
node_modules/heapdump/build/Release/obj.target
node_modules/heapdump/build/Release/obj.target/addon
node_modules/heapdump/build/Release/obj.target/addon/src
node_modules/heapdump/build/Release/obj.target/addon/src/heapdump.o
node_modules/heapdump/build/Release/.deps
node_modules/heapdump/build/Release/.deps/Release
node_modules/heapdump/build/Release/.deps/Release/obj.target
node_modules/heapdump/build/Release/.deps/Release/obj.target/addon
node_modules/heapdump/build/Release/.deps/Release/obj.target/addon/src
node_modules/heapdump/build/Release/.deps/Release/obj.target/addon/src/heapdump.o.d
node_modules/heapdump/build/Release/.deps/Release/addon.node.d
node_modules/heapdump/build/addon.target.mk
node_modules/heapdump/build/config.gypi
node_modules/heapdump/build/binding.Makefile
node_modules/heapdump/build/node_gyp_bins
node_modules/heapdump/build/node_gyp_bins/python3
node_modules/heapdump/src
node_modules/heapdump/src/heapdump-posix.h
node_modules/heapdump/src/heapdump.cc
node_modules/heapdump/src/heapdump-win32.h
bnoordhuis commented 1 year ago

Looks healthy. What does file node_modules/heapdump/build/Release/addon.node print?

laurencefass commented 1 year ago

I assume you refer to addon.node.d?

cat node_modules/heapdump/build/Release/.deps/Release/addon.node.d

cmd_Release/addon.node := c++ -bundle -undefined dynamic_lookup -Wl,-search_paths_first -mmacosx-version-min=10.13 -arch arm64 -L./Release -stdlib=libc++  -o Release/addon.node Release/obj.target/addon/src/heapdump.o
bnoordhuis commented 1 year ago

No, the exact command I posted. uname -a would be helpful too.

laurencefass commented 1 year ago

sure, thanks.

nest-mono % file node_modules/heapdump/build/Release/addon.node
node_modules/heapdump/build/Release/addon.node: Mach-O 64-bit bundle arm64

and

nest-mono % uname -a
Darwin rp-2114.racingpost.local 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 arm64

thank you.

bnoordhuis commented 1 year ago

Looks a-okay. I don't know why you're having trouble but heapdump itself seems to be just fine. One final test you can try is check what this prints:

$ node -p 'require("./node_modules/heapdump/build/Release/addon.node")'
HadrienPierart commented 1 year ago

Im getting a similar issue on Linux.

make: Entering directory '/home/xyz/data/node_modules/heapdump/build'
  CXX(target) Release/obj.target/addon/src/heapdump.o
make: g++: No such file or directory
make: *** [addon.target.mk:113: Release/obj.target/addon/src/heapdump.o] Error 127
make: Leaving directory '/home/xyz/data/node_modules/heapdump/build'

Node v16.19 gyp : 9.4.0

rm -rf node_modules sudo apt-get install build-essential

Problem solved. In case it would help you of someone else...

croccifixio commented 7 months ago

As of v11.13.0, Node has built-in functionality for taking snapshots:

import { getHeapSnapshot } from "v8";

const stream = getHeapSnapshot(); // returns a readable stream of the heap snapshot
import { writeHeapSnapshot } from "v8";

writeHeapSnapshot(); // writes the heap snapshot to a file