question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Always get wrong NODE_MODULE_VERSION installing sharp with Docker

See original GitHub issue

I’m having a difficult time trying to set up a new environment on Digital Ocean with Docker. Sharp is one of my dependencies. The container never gets up and when I see the logs I find:

The module ‘/app/node_modules/sharp/build/Release/sharp.node’ was compiled against a different Node.js version using NODE_MODULE_VERSION 64. This version of Node.js requires NODE_MODULE_VERSION 67. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install).

If I change the version of Node in the Image, the NODE_MODULE_VERSION message changes. For example, it says “Compiled with NODE_MODULE_VERSION 67 but needs 72”. So anytime I change the Node version, I get a different NODE_MODULE_VERSION error.

I restarted and reinstalled docker, restarted the system, nothing seems to solve the problem.

Anyone know what could that be?

Dockerfile

FROM node:11
WORKDIR /app
RUN rm -rf /app/*
COPY package.json /app
RUN npm install
RUN npm rebuild
COPY . /app
CMD NODE_ENV=production node app.js
EXPOSE 8091

Sharp version "sharp": "0.22.1", Running compose with commands

sudo docker-compose down -v --rmi all
sudo docker-compose up --force-recreate --build -d
docker rmi $(docker images --filter “dangling=true” -q --no-trunc)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
justinmchasecommented, Oct 14, 2019

I think your problem is in your Dockerfile this line:

COPY . /app

You are copying package.json and running npm install in previous steps and then you are copying . into the container, which would include your local node_modules folder if you have one and override the files in the docker container.

Sharp has a native module in it, which means when you install it will compile some C++ based on your nodejs version and operating system. That will then live in node_modules. If you switch versions of nodejs or copy them to another operating system they won’t necessarily work. You need to copy all of your code except node modules and then run npm install later. Also, you should copy your package-lock.json file during initial npm install, btw.

Unfortunately dockerfile doesn’t support great wildcard semantics in COPY so you may end up doing something like this:

COPY package*.json /app
COPY ./src /app/src
COPY ./tsconfig.json /app

Etc.

You also don’t need either of these lines in your file:

RUN rm -rf /app/*
RUN npm rebuild

Every time you build the container it will be like doing it from scratch.

0reactions
lovellcommented, Nov 13, 2019

Closing due to inactivity but please feel free to reopen with more details if further help is required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error installing Sharp in docker container - npm - Stack Overflow
In my case after trying a lot of different options from scouring the github issues for Sharp, the addition of this line to...
Read more >
Something went wrong installing the "sharp" module (fix)
I've tried every solution I could find on Google, but nothing has worked so far. The fix: downgrade Node.js. When I downgrade my...
Read more >
Docker Build: Creating Secure Node.js images with Liran Tal
Inspired by an active community and by transparent, open source innovation, Docker containers have been downloaded more than 700 million ...
Read more >
Dockerfile npm build fails with wrong node_module_version ...
I'm getting the The module xxx was compiled against a different Node.js version using NODE_MODULE_VERSION xx.
Read more >
Getting Started with Docker Using Node.js(Part I)
Router(), false, true ) ) server.start() ... Before we can run npm install, we need to get our package.json and package-lock.json file s ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found