211

I am getting below yarn error when deploying to AWS

error fs-extra@7.0.1: The engine "node" is incompatible with this module. Expected version ">=6 <7 || >=8". Got "7.0.0"

Any idea how will this be resolved?

Will this work out if I specify engine in package.json

{ 
  "engines" : { 
    "node" : ">=8.0.0" 
  }
}
tk421
  • 5,557
  • 6
  • 23
  • 33
JN_newbie
  • 4,022
  • 9
  • 52
  • 85
  • 1
    yes , you are getting this error because of incompatibility between the package version and node engine. – Shubham Sharma Jun 16 '19 at 09:45
  • @ShubhamSharma, Thank you. if I specify engine block in the package.json then I will not get any error right? I am gonna try this out then – JN_newbie Jun 16 '19 at 10:58
  • Try adding .node-version or .nvmrc file to the site’s base directory in your repository. – Shardul Dec 20 '21 at 19:23

14 Answers14

258

You can try to ignore the engines :

$ yarn install --ignore-engines

OR

$ yarn global add <your app> --ignore-engines

You can see all what you can ignore by running:

$ yarn help | grep -- --ignore

--ignore-scripts     don't run lifecycle scripts
--ignore-platform    ignore platform checks
--ignore-engines     ignore engines check
--ignore-optional    ignore optional dependencies
Amine Zaine
  • 135
  • 1
  • 18
Alécio Cruz
  • 2,697
  • 1
  • 11
  • 4
  • 12
    Or, as Peter answered below, just run `yarn config set ignore-engines true` to disable this invasive check permanently on the whole system. – Nabil Freeman Sep 18 '21 at 11:04
121

You need to upgrade your version of node.

I ran into this same issue.

If you used Homebrew run:

brew update  # This updates Homebrew to latest version
brew upgrade node

If you use nvm run:

nvm current node -v  # Checks your current version
nvm install <version>  # Example: nvm install 12.14.1

For the above step go to https://nodejs.org/en/download/

Grab a version which satisfies the conditionals in your error, the latest version should work.

More Detailed Walkthrough: https://flaviocopes.com/how-to-update-node/

Ronan Boiteau
  • 8,910
  • 6
  • 33
  • 52
David Arango
  • 1,404
  • 1
  • 10
  • 7
  • 4
    Optionally, if you need a specific, and not latest, version of node, you can do this: `brew update; brew search node; brew unlink node; brew install node@12` – J.Z. Mar 25 '20 at 17:41
  • You should mention "If you are not windows user" in the answer. – Sanan Ali Sep 16 '21 at 14:05
  • 2
    @J.Z. you forgot the last step to link the installed version `brew link node@12 ` – azizbro Sep 25 '21 at 14:15
  • still have the same error even though after updating I got "node 17.3.0 already installed" Do you know how to fix it? – Lydia Dec 23 '21 at 16:28
93

A fix that is a hack can be

yarn config set ignore-engines true

However if you want a permanent solution is to :

  1. delete node_modules/, package-lock.json & yarn.lock
  2. run yarn install or npm i again.
Peter Hassaballah
  • 1,195
  • 8
  • 16
  • 4
    Deleting yarn.lock and doing yarn install again worked for me, and seems the most sensible solution - I cloned a repo I hadn't touched for years, and my node version has been upgraded since - the error was because yarn.lock was telling yarn to expect a certain node version - in my case, 'Expected version ">=4 <=9". Got "16.1.0"' - so delete yarn.lock. – drkvogel May 24 '21 at 13:21
  • thank you! that worked. – Adam Dec 30 '21 at 21:56
29

Add --ignore-engines to the suffix while installing the package like this:

yarn add <package_name> --ignore-engines

cmcodes
  • 1,154
  • 15
  • 21
  • 1
    Thanks for this :) I wouldn't recommend ignoring anything, but hey, in local it's all good :D – LukyVj Apr 01 '21 at 09:38
16

My problem was solved with yarn --ignore-engines, but I'm not sure why and how.

Shashank Agrawal
  • 23,503
  • 10
  • 80
  • 110
maryam
  • 197
  • 1
  • 7
9

I had a similar issue on Ubuntu even after installing Nodejs many times with the latest version, it was showing always the same old Nodejs version; I discovered it was installing the similar old Debian package each time, even after executing the apt-get update command

Finally, I got it to work by purging the old nodeJs then adding different repository source, and installing nodeJs normally with the new distribution as follows:

sudo apt-get purge --auto-remove nodejs
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

Please find the list of all NodeJs distribution below https://github.com/nodesource/distributions/blob/master/README.md

You may find other ways of doing the update, but this one worked for me.

Hany Sakr
  • 2,113
  • 23
  • 23
4

You can try:

  1. Open you package.json
  2. find "engines": { "node": "14.x" }
  3. change 14.x -> >=14.x
Andrey Patseiko
  • 2,682
  • 21
  • 20
3

What worked for me was to update Node to the latest version. Following any tutorial depending on your OS.

Upgrading Node.js to latest version

ivandax
  • 437
  • 5
  • 5
3

I recommend doing what the error message says and checking your Node.js version (node -v). The easiest way to upgrade Node.js is with the n version manager:

$ npm install -g n

Then install the latest (n latest) or LTS (n lts) version of Node.

MMK21
  • 59
  • 2
  • 5
2
sudo npm cache clean -f
sudo npm install -g n
sudo n 10.22.1
node -v => Should be on 10.22.1

type what version of node you require as I have just put 10.22.1 as an example

  • 7
    This user is trying to manage their packages with yarn. It would probably be a good idea to stick to answering the question with the tools they're using. I'm no js expert, but I know that mixing yarn & npm can lead to strange behaviors. – Strifey Apr 07 '21 at 18:42
2

I do NOT recommend using this:

% yarn install --ignore-engines

It avoids the issue instead of solving it.
A possible solution would be to update your node to version > 8.0.

% brew upgrade node

Or you could try installing multiple versions of node by using nodenv, in case you need them for other projects.

% brew install nodenv
% nodenv init
# Load nodenv automatically by appending
# the following to ~/.zshrc:

eval "$(nodenv init -)"
% nodenv install 6.0.0 //or some other version
0

I found this problem now, with an old code, however, I solved it with: yarn upgrade

  • It's not a problem to provide a simple solution, but your answer should be more complete. For instance, you could provide a complete step-by-step answer to accomplish a more complete solution. – Francisco Maria Calisto Mar 31 '21 at 11:06
0

Just found that not only I need to upgrade the node, but also need to install it.

This upgrades node to latest version:

brew upgrade node

This install the specific version of node:

nvm install 17.0.0
Deqing
  • 12,998
  • 13
  • 78
  • 120
0

Update your Node.js to the latest version.

https://nodejs.org/en/download/