327

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,775
  • 6
  • 23
  • 34
JN_newbie
  • 5,492
  • 14
  • 59
  • 97
  • 4
    yes , you are getting this error because of incompatibility between the package version and node engine. – Shubham Sharma Jun 16 '19 at 09:45
  • 1
    @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
  • 2
    Try adding .node-version or .nvmrc file to the site’s base directory in your repository. – Shardul Dec 20 '21 at 19:23

24 Answers24

393

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
  • 165
  • 1
  • 21
Alécio Cruz
  • 4,054
  • 1
  • 12
  • 6
  • 26
    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
  • 8
    Another option besides ignoring the version error is to actually update your node version using something like `nvm install 16.16.0` and then `nvm use 16.16.0`. These will update your local `.nvmrc` which specifies a per-project node version. Choose a stable long-term support (LTS) candidate that from this page, and make sure it matches the expected versions from the error message as well: https://nodejs.org/en/about/releases/ – Hartley Brody Aug 05 '22 at 18:57
154

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 Node.js - Downloads

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

More Detailed Walkthrough: How to update Node.js

Abdullah Khawer
  • 4,461
  • 4
  • 29
  • 66
David Arango
  • 1,830
  • 1
  • 11
  • 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? – glushkina1 Dec 23 '21 at 16:28
  • 1
    This worked for me using the version number mentioned in the error. My error was `Expected version ">=16".` so I ran `nvm install 16`. – John Skiles Skinner Sep 20 '22 at 16:45
146

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,757
  • 1
  • 9
  • 18
  • 7
    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
  • Deleting the two lock files (no node_modules folder for my next.js project) worked for me! – Ð.. Jan 11 '23 at 06:53
33

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

yarn add <package_name> --ignore-engines

cmcodes
  • 1,559
  • 19
  • 24
  • 2
    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
20

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
The Blind Hawk
  • 1,199
  • 8
  • 24
18

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

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
maryam
  • 217
  • 2
  • 7
16

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 here: Node.js Binary Distributions

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

Abdullah Khawer
  • 4,461
  • 4
  • 29
  • 66
Hany Sakr
  • 2,591
  • 28
  • 27
  • Probably old configuration files getting in the way. – Teekin Apr 14 '22 at 09:33
  • This worked best for me. Even after trying to use NVM to set the default node version, I had no luck. I removed nvm, and installed node using this solution. Everything works great now. – Matt Budz Mar 21 '23 at 21:05
15

Lots of answers say to set flags to ignore the version error.

A better option is to use this as a reminder to update your node version to something recent and supported by the package you want to install.

nvm install 16.16.0  # download & install locally on your system
nvm use 16.16.0      # update current project's .nvmrc file

Note that the 2nd command will update your local .nvmrc which specifies a per-project node version.

The node ecosystem turns over quickly, even "Long Term Support" (LTS) releases stop getting support after about 3 years. Use this page to see the latest LTS release version, and also make sure it matches the node version expected by the package you're installing, from the error message.

Hartley Brody
  • 8,669
  • 14
  • 37
  • 48
  • 1
    this is likely the right answer in most scenarios, thanks @HartleyBrody – fredrivett Oct 19 '22 at 18:17
  • This is an answer. This is why StackOverflow's losing credibility, there is no explanation of fix solution only a workaround or copy of previous solutions Everybody digging for 'likes'. Kudos @HartleyBrody – AFetter May 23 '23 at 01:01
10

You can try:

  1. Open you package.json
  2. find "engines": { "node": "14.x" }
  3. change 14.x -> >=14.x
Andrey Patseiko
  • 3,687
  • 1
  • 25
  • 24
6

you need to run the below command and your problem will be solved

yarn install --ignore-engines

or

npm install --ignore-engines
Sadiq Rauf
  • 141
  • 2
  • 3
5

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
  • 79
  • 2
  • 5
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
  • 607
  • 6
  • 5
3

Update your Node.js to the latest version.

See: Node.js - Downloads

Abdullah Khawer
  • 4,461
  • 4
  • 29
  • 66
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
1

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
  • 14,098
  • 15
  • 84
  • 131
1

This is a lot more problematic than it seems on the surface.

If you include a module that requires node 6, but you have other modules that use node 11, you will get this error!

It's problematic when it's 3rd party modules you've used nom/yarn/etc. to install, as you don't have access to those package repos without doing git fork.

In my case, I am using yarn workspaces and some of the modules in the package.json files in the workspaces might require foo 1.0 while others require foo 2.0 and the 1.0 version might require node 6 and the 2.0 version might require node 14.

The only solution I found is to use --ignore-engines, though it clearly is what other(s) have posted - that this is not fixing the problem, just ignoring it in spite of any issues that might be caused (node 6 code might not run on node 14!).

mschwartz
  • 63
  • 3
1

Sometimes you cannot upgrade the Node engine (legacy projects, client requirements etc). The solution I found in this case was to downgrade the problematic versions by using "selective dependency resolution", as documented on Yarn: Selective dependency resolutions

{
  "name": "project",
  "version": "1.0.0",
  "dependencies": {
    "left-pad": "1.0.0",
    "c": "file:../c-1",
    "d2": "file:../d2-1"
  },
  "resolutions": {
    "d2/left-pad": "1.1.1",
    "c/**/left-pad": "^1.1.2"
  }
}

Notice the "resolutions" part. You can force those packages to downgraded versions (compatible with your older Node engine).

Abdullah Khawer
  • 4,461
  • 4
  • 29
  • 66
zmx
  • 1,051
  • 1
  • 10
  • 12
0

ignore-engines tells the package manager to ignore the engines filed in the package.json file when installing packages. So when you set ignore-engine to true, you are basically telling Yarn to ignore this field and proceed with the installation regardless of the Node.js.

engines allows package authors to state which node engines are required for the package to work. Basically, which node version is needed. If you ignore this guidance, you run the risk of installing a package that won't work with the version of node that you are using because it relies on a feature that your version of node does not support.

So I find that the best solution is to update the Node version to the recommended version, as follows:

Uninstall the old version of Node.js. This command will remove the old Node.js package and any associated dependencies.

sudo apt autoremove nodejs

Add a different repository source. This will add the NodeSource package repository to the system’s sources list.

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -

Install Node.js from the new repository.

sudo apt-get install -y nodejs
t2fmkh
  • 77
  • 8
0

For anyone using asdf and having this issue, your nodejs plugin version should be upgraded and/or set.

Checking asdf plugin versions:

▶ asdf current
nodejs          16.13.0         Not installed. Run "asdf install nodejs 16.13.0"
poetry          1.2.1           /Users/zack/.tool-versions
python          3.9.9           /Users/zack/.tool-versions

Verify lastest is installed:

▶ asdf install nodejs latest
nodejs 20.1.0 is already installed

Set global version to latest:

▶ asdf global nodejs latest

Verify set:

▶ asdf current
nodejs          20.1.0          /Users/zack/.tool-versions
poetry          1.2.1           /Users/zack/.tool-versions
python          3.9.9           /Users/zack/.tool-versions

Everything worked correctly after this for me.

Zack
  • 1,181
  • 2
  • 11
  • 26
0

yarn add <your_lib> is a bad decision, if there are a lot of libs, which should not ignore engines, and when you run:

yarn add <your_lib> --ignore-engines

some libs won't work in your project.

Akash Sarkar
  • 632
  • 9
  • 20
TerraQBit
  • 9
  • 1
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 01 '23 at 18:22
0

I got this error when building a NextJS app using Docker and Yarn. The error I was getting is:

error next@13.4.2: The engine "node" is incompatible with this module. Expected version ">=16.8.0". Got "14.21.3"

How I solved it:

The issue was that the node version I was using in the Dockerfile was lower than the version expected by the project.

My Dockerfile had the following base image:

FROM node:14-alpine

I had to change it from node:14-alpine to node:lts-alpine:

FROM node:lts-alpine
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
0

Update your node version in build script. I was able to fix this when deploying using github actions. I updated node version from 16.x to 19.x heres the GitHub actions build https://github.com/maheshmnj/blog/actions/runs/6060258443

  node-version: 19.x
Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
-1

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
-1

Upgrade your version of node , this issue will be resolved