Unsupported engine node / NPM only when building in Docker
Asked Answered
R

3

26

I have a dependency in my package.json which itself has the following dependency:

"node-rdkafka": "^2.5.0",

Using nvm on my local machine and setting my node version to 8.9.1, and my npm version is 5.5.1, I can successfully run

npm install [email protected]

But when running the same thing (i.e npm install) from within my docker image:

FROM node:10.13.0-alpine or FROM node:8.9.1-alpine

I get the following error:

npm ERR! notsup Unsupported engine for [email protected]: wanted: {"node":">=12.0.0"} (current: {"node":"10.13.0","npm":"6.4.1"})
npm ERR! notsup Not compatible with your version of node/npm: [email protected]
npm ERR! notsup Not compatible with your version of node/npm: [email protected]
npm ERR! notsup Required: {"node":">=12.0.0"}
npm ERR! notsup Actual:   {"npm":"6.4.1","node":"10.13.0"}

Any ideas about this inconsistency?

I clearly dont need a node version this high. But it says I do.

Rurik answered 13/9, 2019 at 13:45 Comment(4)
are you sure that it is working correctly on your local environment (the one with nvm) from the logs you could expect that there were probably some breaking changes that should not be allowed, if anything it's not an issue with docker but with your local node install that tricks the library to ignore node versionArcheology
the weird thing is that the minimal setup (simple docker file with FROM node:10.13.0 RUN npm install [email protected]) builds correctly for me, granted i don't use alpine because rdkafka required python executable and some other stuff i don't want to deal with settting up... could you provide entire package.json and Dockerfile ?Archeology
Hmm.. I still get the same problem with FROM node:10.13.0Rurik
FYI it was because there was a setting engine-strict=true in .npmrc fileRurik
C
12

Try to remove package-lock.json before npm install in Docker

rm package-lock.json
npm i
Cere answered 13/9, 2019 at 16:31 Comment(2)
That doesn't fix it for me.Precursor
It also defeats the purpose of package-lock.json.Aggri
F
11

The engines property in the package.json allows us to establish a range of versions.

With >=12 is asking for a node with version 12 or greater.

Therefore, the solution would be to install the requested version:

FROM node:12

I recommend reviewing the versions currently available on Docker here.

Fernand answered 10/5, 2021 at 8:50 Comment(0)
P
1

When building old apps with a more recent nodejs, it might work perfectly fine to use older packages which had requirements on nodejs engine.

Karma package, for instance, has this requirement : required: { node: '0.10 || 0.12 || 4 || 5 || 6 || 7' }. But it works ok in nodejs 16.

In this case, there is a setting to transform EBADENGINE into a error or warning. It works in nodejs 16 at least.

Add or remove this line in your ~/.npmrc : engine-strict=true.

I added this flag following a tutorial, and didn't realize its impact until I wanted to build an older app.

Padauk answered 25/9, 2023 at 11:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.