22

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 node-rdkafka@2.7.1

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 node-rdkafka@2.7.1: 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: node-rdkafka@2.7.1
npm ERR! notsup Not compatible with your version of node/npm: node-rdkafka@2.7.1
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.

Greg Peckory
  • 7,700
  • 21
  • 67
  • 114
  • 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 version – Krzysztof Krzeszewski Sep 13 '19 at 13:52
  • the weird thing is that the minimal setup (simple docker file with `FROM node:10.13.0 RUN npm install node-rdkafka@2.7.1`) 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` ? – Krzysztof Krzeszewski Sep 13 '19 at 14:02
  • Hmm.. I still get the same problem with `FROM node:10.13.0` – Greg Peckory Sep 13 '19 at 14:55
  • 4
    FYI it was because there was a setting `engine-strict=true` in `.npmrc` file – Greg Peckory Sep 13 '19 at 15:43

2 Answers2

14

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

rm package-lock.json
npm i
Andrew
  • 693
  • 3
  • 5
9

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

Anyway, I recommend reviewing the versions supported by Docker currently here.

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29