I am trying to install heapdump package(https://www.npmjs.com/package/heapdump) in my node code base to get the memory usage details. While building the docker image using mhart/alpine-node:14, image is getting built but container is not getting started with below error.
{"severity":"error","time":1660281464875,"pid":7,"hostname":"1fefc680cf00","stack":"Error: Error relocating /app/node_modules/heapdump/build/Release/addon.node: _ZN2v812HeapProfiler16TakeHeapSnapshotEPNS_15ActivityControlEPNS0_18ObjectNameResolverEb: symbol not found\n at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)\n at Module.load (internal/modules/cjs/loader.js:863:32)\n at Function.Module._load (internal/modules/cjs/loader.js:708:14)\n at Module.require (internal/modules/cjs/loader.js:887:19)\n at require (internal/modules/cjs/helpers.js:74:18)\n at Object.<anonymous> (/app/node_modules/heapdump/index.js:16:15)\n at Module._compile (internal/modules/cjs/loader.js:999:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)\n at Module.load (internal/modules/cjs/loader.js:863:32)\n at Function.Module._load (internal/modules/cjs/loader.js:708:14)","type":"Error","message":"Error relocating /app/node_modules/heapdump/build/Release/addon.node: _ZN2v812HeapProfiler16TakeHeapSnapshotEPNS_15ActivityControlEPNS0_18ObjectNameResolverEb: symbol not found"
First I thought this error is because of node-gyp rebuild due to python missing and added the below commands in docker file.
FROM mhart/alpine-node:14 as builder
WORKDIR /app
COPY . /app
ARG NPM_USERNAME
ARG NPM_TOKEN
# Add python packages
# hadolint ignore=DL4006
# RUN which python
# Upstream bug with hadolint ordering
# hadolint ignore=DL4006
RUN apk add --no-cache binutils=2.33.1-r1 && \
echo "$NPM_USERNAME:$NPM_TOKEN" > /tmp/auth && \
npm config set update-notifier false && \
# hadolint ignore=DL4006
apk add --update python3 make g++\
&& rm -rf /var/cache/apk/*\
&& python3 --version\
&& which python3\
&& npm config set python "/usr/bin/python3"\
&& npm ci --no-audit --production\
&& strip /usr/bin/node
FROM alpine:3.12
WORKDIR /app
COPY --from=builder /usr/bin/node /usr/bin/
COPY --from=builder /usr/lib/libgcc* /usr/lib/libstdc* /usr/lib/
COPY --from=builder /app /app
#COPY --from=builder /app/node_modules /app/node_modules
RUN apk add --no-cache tini=0.19.0-r0
RUN apk add --no-cache curl=7.79.1-r1
RUN apk add --no-cache npm=12.22.12-r0
ENV PORT=4444 \
NODE_ENV=production \
MAX_EVENT_LOOP_DELAY=1000 \
MAX_RSS_BYTES=0 \
MAX_HEAP_USED_BYTES=0 \
MAX_AGE=86400
EXPOSE $PORT
# an init entrypoint that simplifies signal handling
ENTRYPOINT ["tini", "--"]
CMD ["sh","-c","node src/index.js"]
This is installing python without any issues and giving output like
#13 24.48 Python 3.8.10
#13 24.48 /usr/bin/python3
Along with this while rebuilding I am getting a waring like
#13 38.55 > heapdump@0.3.15 install /app/node_modules/heapdump
#13 38.55 > node-gyp rebuild
#13 38.55
#13 58.52 make: Entering directory '/app/node_modules/heapdump/build'
#13 58.52 CXX(target) Release/obj.target/addon/src/heapdump.o
#13 59.12 In file included from ../src/heapdump.cc:15:
#13 59.12 /root/.cache/node-gyp/14.17.3/include/node/node.h:758:43: warning: cast between incompatible function types from 'void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)' {aka 'void (*)(v8::Local<v8::Object>)'} to 'node::addon_register_func' {aka 'void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)'} [-Wcast-function-type]
#13 59.12 758 | (node::addon_register_func) (regfunc), \
#13 59.12 | ^
#13 59.12 /root/.cache/node-gyp/14.17.3/include/node/node.h:792:3: note: in expansion of macro 'NODE_MODULE_X'
#13 59.12 792 | NODE_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
#13 59.12 | ^~~~~~~~~~~~~
#13 59.12 ../src/heapdump.cc:136:1: note: in expansion of macro 'NODE_MODULE'
#13 59.12 136 | NODE_MODULE(addon, Initialize)
#13 59.12 | ^~~~~~~~~~~
#13 59.37 SOLINK_MODULE(target) Release/obj.target/addon.node
#13 59.40 COPY Release/addon.node
#13 59.40 make: Leaving directory '/app/node_modules/heapdump/build'
This is causing the issue i believe
I am using mhart/alpine-node:14
with below versions
node: v14.17.3
npm: v6.14.13
Also I am using heapdump of version 0.3.15
Can someone please help to figure out what is the issue happening here?