11

I try to do a yarn add, but I have this error:

The engine "node" is incompatible with this module. Expected version "12.x". Got "14.8.0"
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Anroche
  • 618
  • 1
  • 8
  • 19

4 Answers4

17

Run these commands:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Then in your project directory run:

rm -r ./node_modules
rm ./yarn.lock

After this, yarn install | add | upgrade should work as expected.

P.S. If you are using the npm package manager, instead of rm ./yarn.lock run rm ./package-lock.json.

zilijonas
  • 3,285
  • 3
  • 26
  • 49
  • what does `npm install -g n` do? Does n refer to node? And how does that interact with setting node via nvm? – Hyetigran Mar 19 '23 at 01:11
  • 1
    @Hyetigran The "n" package is a Node.js version management utility that allows you to easily switch between different versions of Node.js on your system. Once you have installed "n", you can use it to install or switch to a different version of Node.js by typing "n " in your terminal. For example, "n 14.17.6" would install or switch to version 14.17.6 of Node.js. In this case "n stable" switches to the latest stable Node version. – zilijonas Mar 21 '23 at 17:16
9

One time fix for the "the engine node is incompatible with this module" problem.

$ yarn install --ignore-engines
Lee Derting
  • 146
  • 1
  • 4
8

I can suggest 2 solutions :

1/ It works but it's probably not the best way

You just have to update your packages.json.

currently :

 "engines": {
     "node": "12.x"
 }

updated :

 "engines": {
     "node": "14.8.0"
 }

2/ I think it's a cleaner way

You can use nvm use x to use the Node version.

exemple : nvm use 14 to use node version 14

Anroche
  • 618
  • 1
  • 8
  • 19
3

I had the same problem when I try to make a new app with react. When I do npx create-react-app my-app, I get this error:

babel-jest@27.4.5: the engine "node" is incompatible with this module. expected version "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0". got "14.8.0" I solved this problem with this which I found this on other stockoverflow answer. I can't install react using npx create-react-app?

npm install -g create-react-app 

This may help you.

johannchopin
  • 13,720
  • 10
  • 55
  • 101
Yahya
  • 51
  • 6