339

I am getting below yarn error when deploying to AWS

error [email protected]: 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" 
  }
}
3
  • 4
    yes , you are getting this error because of incompatibility between the package version and node engine. Jun 16, 2019 at 9: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, 2019 at 10:58
  • 2
    Try adding .node-version or .nvmrc file to the site’s base directory in your repository.
    – Shardul
    Dec 20, 2021 at 19:23

24 Answers 24

410

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
2
  • 28
    Or, as Peter answered below, just run yarn config set ignore-engines true to disable this invasive check permanently on the whole system. Sep 18, 2021 at 11:04
  • 9
    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: nodejs.org/en/about/releases Aug 5, 2022 at 18:57
158

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

5
  • 5
    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, 2020 at 17:41
  • You should mention "If you are not windows user" in the answer.
    – Sanan Ali
    Sep 16, 2021 at 14:05
  • 2
    @J.Z. you forgot the last step to link the installed version brew link node@12
    – azizbro
    Sep 25, 2021 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, 2021 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. Sep 20, 2022 at 16:45
150

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.
3
  • 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, 2021 at 13:21
  • thank you! that worked.
    – Adam
    Dec 30, 2021 at 21:56
  • Deleting the two lock files (no node_modules folder for my next.js project) worked for me!
    – Ð..
    Jan 11 at 6:53
34

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

yarn add <package_name> --ignore-engines

1
  • 2
    Thanks for this :) I wouldn't recommend ignoring anything, but hey, in local it's all good :D
    – LukyVj
    Apr 1, 2021 at 9:38
21

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 manage multiple node versions by using nodenv or nvm, 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
1
  • 1
    nvm is an alternative tool to manage your node versions
    – rosalynnas
    Mar 2 at 19:39
18

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

18

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.

3
  • 2
    this is likely the right answer in most scenarios, thanks @HartleyBrody
    – fredrivett
    Oct 19, 2022 at 18:17
  • 1
    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 at 1:01
  • My answer is just over a year old and already the node version I included 16.16.0 is almost at the end of its life! Sep 28 at 20:23
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.

2
  • Probably old configuration files getting in the way.
    – Teekin
    Apr 14, 2022 at 9: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 at 21:05
11

You can try:

  1. Open you package.json
  2. find "engines": { "node": "14.x" }
  3. change 14.x -> >=14.x
1
  • what does this actually do? what is the underlying context meaning? thanks
    – mattsmith5
    Jun 26 at 3:53
6

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

yarn install --ignore-engines

or

npm install --ignore-engines
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.

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

3

Update your Node.js to the latest version.

See: Node.js - Downloads

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

1
  • 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 7, 2021 at 18:42
2

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).

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
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!).

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

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.

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.
    – Community Bot
    Jun 1 at 18:22
0

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

error [email protected]: 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
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
-1

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

1
  • 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. Mar 31, 2021 at 11:06
-1

Upgrade your version of node , this issue will be resolved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.