83

When generating a package-lock.json file using npm install, I get this error:

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'app@1.0.0',
npm WARN EBADENGINE   required: { node: '16.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.10.0', npm: '7.24.0' }
npm WARN EBADENGINE }

I'm a little confused here. It requires Node v16.0.0, and that's the one I'm using. Isn't npm v7.x.x compatible with that version of node?

Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
calyxofheld
  • 1,538
  • 3
  • 24
  • 62

5 Answers5

62

You are using 16.10.0, but the message says it requires 16.0.0. Not 16.0.0 or greater. It requires exactly 16.0.0.

If it's your package.json with the engines field causing this issue, change it to say 16.0.0 or greater:

  "engines": {
    "node": ">=16.0.0"
  },
Trott
  • 66,479
  • 23
  • 173
  • 212
  • 2
    If you dont find that in the `package.json` file you might need to do that on your `pakage-lock.json` and then try the npm install command again – Mauricio Gracia Gutierrez May 13 '22 at 02:14
  • 3
    Note that `>=16.0.0` includes all future versions, which can include breaking changes in major versions. More robust version strings would be `^16.0.0`, `^16`, or `16.x` which restrict to major version `16`. See https://semver.npmjs.com/ for more info. – victorlin Oct 21 '22 at 18:01
  • Thanks! This fixed a [recent deployment of mine](https://github.com/awwsmm/awwsmm.com/pull/142) on Vercel using Next.js where next was bumped from 13.3.1 to 13.4.1. I got an error "SyntaxError: Unexpected token '??='" and a log message "npm WARN EBADENGINE Unsupported engine". Forcing the node engine version to `">=16.8.0"` in `package.json` fixed the issue. Adding all the context here for googleability. Note, Vercel users, that there is also a "Node.js Version" setting in the UI at vercel.com///settings – awwsmm May 09 '23 at 14:30
10

If you are using nvm run

nvm install 18.1.0
nvm use 18.1.0

If you don't have nvm installed follow this tutorial

Toheeb
  • 1,217
  • 1
  • 14
  • 26
  • 1
    Using a tool to manage node versions is a good idea -- but **fnm** (https://github.com/Schniz/fnm) is a better choice than nvm. It has a similar API (including support for reading .nvmrc files to switch versions on cd into given dir), but it's faster and less disruptive to your shell / env. – cweekly Oct 28 '22 at 16:13
  • 18.1.0 not found for macbook.. try instead 18.16.0 – Kieran Ryan Apr 18 '23 at 14:44
  • 1
    Thanks yeah, although the accepted answer provides more information on the cause of the issue, this is the solution I actually used. Obviously it doesn't have to be 18.1.0 but rather just whatever matches with the engine requirements in your package. – emery Aug 28 '23 at 18:28
3

at package.lock.json, do this:

 "engines": {
    "node": ">=0.7.0 <16.15.0"
  }

This will almost support all nodejs npm modules.

see this line

npm WARN EBADENGINE   required: { node: '>= 0.8.0 < 0.11.0' },

this meant node engine should have range anywhere between 0.8.0 and 0.11.0, e.g. engines": {"node": ">=0.7.0 <16.15.0"} or engines": {"node": ">=0.9.0 <11.15.0"} etc.

aakash4dev
  • 774
  • 4
  • 13
  • 1
    As I understand it, it's rarely a good idea to manually edit the package.lock file. – Navelgazer Dec 09 '22 at 00:07
  • it's bad practice to edit package.json NPM LIBRARIES, and never edit when you don't know what package.json does. but i know what it does. If you find any other way, tell me, i am also finding its alter method. – aakash4dev Dec 12 '22 at 16:02
  • once you get more senior level it's not bad practice to alter your package.json npm dependencies. But simply using the right version of node may be all that's needed here. – emery Aug 28 '23 at 18:30
3

I ended up editing the 'engines' entry in package.json for the project to precisely match what was installed on my machine (the versions of both my node and npm matched the requirements in spite of the error telling me otherwise).

Before (in package.json):

"engines": {
    "node": "^18.14.1",
    "npm": "^9.5.0"
 },

Which threw the following error on npm install:

...
npm ERR! notsup Required: {"node":"^18.14.1","npm":"^9.5.0"}
npm ERR! notsup Actual:   {"npm":"9.6.1","node":"v19.7.0"}

npm ERR! A complete log of this run can be found in:
...

After:

"engines": {
    "npm": "9.6.1",
    "node" : "v19.7.0"
 },

Nb. I included the 'v' in the version number as per a comment on the original question (although I didn't confirm whether that was the issue or not).

wkille
  • 543
  • 6
  • 12
  • I also had an issue with the versioning not working well and the "v" appearing in my local installation's version info. Following your approach I was able to compile the target code without any problem. This was the quick help I was looking for. – LastZolex Jun 09 '23 at 06:15
3

This problem took so much of my time, what I did finally was I downloaded the required version of node from here >>> https://nodejs.org/en

After downloading and installing the new node, just rerun npm install inside the directory of your project. It sorted my problem,

Awara Amini
  • 307
  • 1
  • 6