I encountered this error recently when attempting run an executable NodeJS file. This error was due to a mismatch of the currently installed npm packages against my NodeJS version.
What Caused The Error?
I installed my NPM packages and thereafter upgraded my NodeJS version to 14.x. As my NPM packages had stuff like node-gyp which compiles against my current OS and NodeJS, it causes a mismatched and threw this error.
Simply run the following command in your NodeJS application folder.
If you are running Docker, check if your npm packages are installed and compiled from within the Docker container. Sometimes, it might be due to it being installed and compiled on the host system and then thereafter being mounted instead of the former. Hence, this results in a mismatch as well.
Run the above command while being inside the Docker container to ensure that everything is installed and compiled against your Docker’s NodeJS version instead of your host node’s NodeJS version.