116

Given this package.json:

{
  "name": "yarn-install-fail",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {},
  "author": "",
  "license": "ISC",
  "dependencies": {
    "aws-sdk": "2.x.x",
    "s3-streams": "^0.3.0"
  }
}

I can install the dependencies successfully via npm:

$ npm install

added 27 packages in 1.844s

Yet yarn fails:

$ yarn install
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
error s3-streams@0.3.0: The engine "node" is incompatible with this module. Expected version "^1.2.0".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

It appears yarn has trouble installing the library s3-streams@0.3.0, yet I assumed it would fallback to install all the dependencies anyway like npm would.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347

5 Answers5

197

You can indeed ignore such errors via --ignore-engines:

$ yarn install --ignore-engines
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 1.41s.

This is also documented in the command's help:

$ 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
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • 13
    Hello! Can I do such thing in npm? – Serge Sep 10 '18 at 08:09
  • Hi! How does it work with scripts like test, for example, yarn test --ignore-engines. Does it work? I don't think it works. That's why I'm asking. The problem I'm facing is I get that trouble when doing yarn test. – sunsets Nov 06 '19 at 07:24
  • @sunsets Scripts are placeholder for any command. So without details to what you are trying to execute, it could be anything. I assume that your `test` script at one point executes a `yarn install` without `--ignore-engine`. Adding a flag to a script does not mean it will be passed down to all the other commands in that chain. – k0pernikus Nov 06 '19 at 10:15
  • The error still shows up when you issue: 'yarn start' command – Abhinav Saxena Mar 02 '22 at 10:32
  • Then this answer in the same question will help : https://stackoverflow.com/a/61102972/787399 (just remove the engine section from your package.json, if it exists). – Abhinav Saxena Mar 02 '22 at 10:57
  • yarn install --ignore-engines worked for me, so thanks! – skittlebiz Nov 01 '22 at 19:04
89

yarn config set ignore-engines true is a one time fix for the "the engine node is incompatible with this module" problem. Once that is completed, you can do "create-react-app my-app"

Luke Phillips
  • 3,372
  • 1
  • 11
  • 15
  • 3
    We added it into the preinstall task: `"preinstall": "yarn config set ignore-engines true",` :) – Guntram Dec 06 '22 at 12:22
10

--ignore-engines doesn't work with the yarn start command

So there are two solutions for that to get rid of it.

check your node version with:

node -v

check your npm version with:

npm -v

Open package.json and make sure the values you got from running the two commands above match with the versions of node and npm in the engines object.

OR

You can simply remove engines from the package.json file otherwise it will always check the version to match.

Mahendra Pratap
  • 3,174
  • 5
  • 23
  • 45
  • 1
    Removing the `engines` field from `package.json` works for me while running `yarn run start`. My problem was due to the version of `node and npm` on my local system is different from the one on the server on digitalOcean. – AWE FRANCIS OLAWUMI Mar 21 '23 at 16:08
7

add --ignore-engines to remove the errors

 $ yarn help 
....
    --ignore-scripts                  don't run lifecycle scripts
    --ignore-platform                 ignore platform checks
    --ignore-engines                  ignore engines check
    --ignore-optional                 ignore optional dependencies
....

Mehul Nirala
  • 163
  • 2
  • 7
1

If you run into this problem, it might be because you have several versions of node on your system.

For example, you might have run some command that installs an uptodate version of node in one place, but be running a different version of node because it's directory is ahead of the other one in $PATH.

So it might be a good idea to run

which -a node

If the nvm version is out-of-date, you could update it, e.g. to a particular version: nvm install 15.4.0

peak
  • 105,803
  • 17
  • 152
  • 177