failed to build native modules on after node 16 upgrade and MacOS upgrade
Question:
I’ve upgrade to MacOS Monterey (12.3.1) and Node 16. Since then I’m failed running installation on some node modules due to @newrelic/native-metrics
with the following error:
Error running install script for optional dependency: "/Users/zivl/github/data-science-client/serverless/ml-platform-services/node_modules/@newrelic/native-metrics: Command failed.
Exit code: 1
Command: node ./lib/pre-build.js install native_metrics
when digging in the logs, I’ve found it is using node-gyp
and python
so I thought maybe due to upgrading I will need to re-install them – so I did so. but reinstalling node-gyp
/ python
(inc. switching multiple python
versions (3.7, 3.9, 3.10) – still didn’t help.
I checked the node-gyp logs and saw the following:
node-pre-gyp http 404 https://github.com/hyj1991/v8-profiler-node8/releases/download/v6.3.0/profiler-v6.3.0-node-v93-darwin-x64.tar.gz
node-pre-gyp WARN Tried to download(404): https://github.com/hyj1991/v8-profiler-node8/releases/download/v6.3.0/profiler-v6.3.0-node-v93-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v93 ABI, unknown) (falling back to source compile with node-gyp)
...
Failed to execute native-metrics install: No pre-built artifacts to download for your OS/architecture.
the v8-profiler-node8
has no version for node 16.
I’ve trying looking for it online and so far didn’t find any solution 🙁
Answers:
It would be better to eliminate such problem completely.
If possible containerize your app, for example with Docker.
Unless you are writing the application specifically for the Mac OS.
https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
It will make sure this does not happen ever again, may be better than one off solution to this 🙂
Eventually, what helped me solve the issue is doing one of the following:
-
install manually a global package of node-gyp
and you should set the node to run that version only (read more about it online, I’ll try to find links but it is anywhere on the net).
-
switch to yarn 3
and pnpm
and with those package managers the 3rd party scripts are not installed by default as in npm
-
you can always use npm install --ignore-scripts
but it sucks to have this flag everywhere…
-
have two versions of python, python2
and python3
in pypenv
global
I hoped this somehow helped you, other answers and solutions are more than welcome 🙂
I’ve upgrade to MacOS Monterey (12.3.1) and Node 16. Since then I’m failed running installation on some node modules due to @newrelic/native-metrics
with the following error:
Error running install script for optional dependency: "/Users/zivl/github/data-science-client/serverless/ml-platform-services/node_modules/@newrelic/native-metrics: Command failed.
Exit code: 1
Command: node ./lib/pre-build.js install native_metrics
when digging in the logs, I’ve found it is using node-gyp
and python
so I thought maybe due to upgrading I will need to re-install them – so I did so. but reinstalling node-gyp
/ python
(inc. switching multiple python
versions (3.7, 3.9, 3.10) – still didn’t help.
I checked the node-gyp logs and saw the following:
node-pre-gyp http 404 https://github.com/hyj1991/v8-profiler-node8/releases/download/v6.3.0/profiler-v6.3.0-node-v93-darwin-x64.tar.gz
node-pre-gyp WARN Tried to download(404): https://github.com/hyj1991/v8-profiler-node8/releases/download/v6.3.0/profiler-v6.3.0-node-v93-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v93 ABI, unknown) (falling back to source compile with node-gyp)
...
Failed to execute native-metrics install: No pre-built artifacts to download for your OS/architecture.
the v8-profiler-node8
has no version for node 16.
I’ve trying looking for it online and so far didn’t find any solution 🙁
It would be better to eliminate such problem completely.
If possible containerize your app, for example with Docker.
Unless you are writing the application specifically for the Mac OS.
https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
It will make sure this does not happen ever again, may be better than one off solution to this 🙂
Eventually, what helped me solve the issue is doing one of the following:
-
install manually a global package of
node-gyp
and you should set the node to run that version only (read more about it online, I’ll try to find links but it is anywhere on the net). -
switch to
yarn 3
andpnpm
and with those package managers the 3rd party scripts are not installed by default as innpm
-
you can always use
npm install --ignore-scripts
but it sucks to have this flag everywhere… -
have two versions of python,
python2
andpython3
inpypenv
global
I hoped this somehow helped you, other answers and solutions are more than welcome 🙂