Recently, I was working on a NodeJs project in which I opt to use node-jq. While everything works locally, when I deployed the application on an AWS Linux 2 instance, I couldn't get it working by just running npm install.
At first, when you run the npm install command, you won't get any error and if you're installing the latest release, it will show that it exists in the node_modules. However, as you run your application, you'll bump into an error like this:
Error: spawn /home/ec2-user/app/node_modules/node-jq/bin/jq ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:480:16)
at onErrorNT (node:internal/child_process:480:16)
Initially, I thought, I had installed it in my local using the -g (global) param. So I tried to install it in the instance globally — and no luck. Clearing the npm cache didn't help as well.
Going back into the node-jq documentation, it says "By default, node-jq downloads jq on the installation process (when you run npm install node-jq). Downloads the binaries according to your OS."
And that was the clue! Manually checking if jq is installed tells me that running npm install node-jq didn't download the jq package.
As a solution, I opt to manually install the package by running yum install jq and creating a symlink to the path where it's reading the node-jq module.
$ which jq
$ mkdir node_modules/node-jq/bin
$ ln -s /usr/bin/jq /home/ec2-user/app/node_modules/node-jq/bin/jq