Skip to content

Instantly share code, notes, and snippets.

@njh
Last active March 31, 2020 18:59
Bash script to fix node-gyp problems when mocking RPMs on CentOS / RHEL / Fedora
#!/bin/sh
# When mocking RPMs, there is no internet access.
# This means that node-gyp is unable to download the node header
# files and store them in ~/.node-gyp
#
# The node header files are provided by the nodejs-devel RPM.
#
# This script checks if the node headers exist at /usr/include/node
# and copies them to ~/.node-gyp.
NODEVER=`/usr/bin/node --version | cut -c 2-`
if [ -z "$NODEVER" ]; then
echo "Unable to detect node version" >/dev/stderr
else
if [ ! -d $HOME/.node-gyp/$NODEVER ]; then
echo "node headers do not exist at ~/.node-gyp/$NODEVER" >/dev/stderr
if [ -d /usr/include/node ]; then
echo "Copying /usr/include/node to ~/.node-gyp/$NODEVER/include/node" >/dev/stderr
mkdir -p $HOME/.node-gyp/$NODEVER/include
cp -Rf /usr/include/node $HOME/.node-gyp/$NODEVER/include/node
echo 9 > $HOME/.node-gyp/$NODEVER/installVersion
else
echo "/usr/include/node does not exist either - try installing nodejs-devel" >/dev/stderr
fi
fi
fi
@njh
Copy link
Author

njh commented Oct 29, 2018

Much simpler solution is to do this:
export npm_config_nodedir="/usr"

If you are mocking, this problem can be solved by putting config_opts['environment']['npm_config_nodedir'] = '/usr' into /etc/mock/site-defaults.cfg.

See also: bbc/speculate#57

@njh
Copy link
Author

njh commented Mar 31, 2020

Thank you Google and past self! Just spent too long on this again 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment