Always get wrong NODE_MODULE_VERSION installing sharp with Docker
See original GitHub issueI’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
ornpm 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:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
I think your problem is in your
Dockerfile
this line:You are copying package.json and running
npm install
in previous steps and then you are copying.
into the container, which would include your localnode_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:
Etc.
You also don’t need either of these lines in your file:
Every time you build the container it will be like doing it from scratch.
Closing due to inactivity but please feel free to reopen with more details if further help is required.