Photo by Susan Q Yin on Unsplash
How to resolve error `Node package is Incompatible with current version installed`
Hi Techies, I know we are familiar with and have come across so many frustrating errors that can get on your nerves. Here is a recent error I came across while trying to deploy one of my node projects on a hosting provider.
The full error reads;
The engine "node" is incompatible with this module. Expected version ">=14.20.1". Got "14.17.0"
I have deployed my application many times and I never came across this error until I did. There's a first for everything, they say. LOL
Well, I did my research and found that this error is not linked to deployment alone, there are cases where you are trying to install a library and this error pops up.
This error is simply pointing out that there is an incompatibility between the package version in your application and the node engine installed.
So how do we resolve it?
I came across a lot of suggestions on Stack and GitHub such as uninstalling node and reinstalling a newer version of node, or editing your package.json node versions to reflect the version specified. All of which I tried but none worked for me as it made my code messier and threw more errors.
There are four ways to resolve this error.
- Add a .node-version file at the root of your project or repository containing the version of the node specified. This was exactly what I did and the error vanished like the effect of a magician waving his wand. In the .node-version file
14.20.1
The version specified for mine was a version greater than or equal to 14.20.1. If yours is maybe >=14.6.5, you can add that in the .node-version file
14.6.5
Create an environment variable and add NODE_VERSION as a key and the specified version as its value. In the ./config/.env file, using the version specified for mine, simply specify 14.20.1 as the value for NODE_VERSION.
In the .config/env file
NODE_VERSION = 14.20.1
Specify the Node version in the engines directly in your package.json file. This was one of the suggestions I got on GitHub.
In the package.json
"engines": { "node": ">=14.20.1" }
Add a .nvmrc file at the root of your project or repository. This is very similar to the first step of creating a .node-version file. In the .nvmrc file, use the node-specified version recommended for you.
14.20.1
Please note that each step is independent of the other and you can only adopt one of the steps to resolve this error.
Thank you for your continued support.
If you have questions for me, you can reach me on Twitter, LinkedIn or