Unsupported engine node / NPM only when building in Docker error occurs when “there is a mismatch between the Node.js and npm versions specified in a project’s package.json and the versions installed in the Docker image.”
To fix the Unsupported engine node / NPM only when building in Docker error, “remove package-lock.json before npm install in Docker.”
rm package-lock.json
npm i
If the above solution does not work for you, here are some alternate solutions that will work for you!
Choose an Appropriate Docker Base Image
If your project requires a specific Node.js version, use a Docker image that provides that version. For instance, if your project requires Node.js 14, you might use this in DockerFile:
FROM node:14
If you’re unsure which versions are available, check the Docker Hub page for the official Node.js image: Node Docker Official Images.
Install the Correct NPM Version (if needed).
If your project requires a specific npm version, you can install it in your Dockerfile using the npm CLI:
RUN npm install -g npm@6
Replace 6 with whatever version is specified in your package.json.
Check Your Project’s Version Requirements
Look in your project’s package.json file for the engines field. It will look something like this:
"engines": {
"node": "14.x",
"npm": "6.x"
}
The above example specifies that the project requires Node.js version 14 and npm version 6.
Rebuild Your Docker Image
Once you have made the necessary changes to your Dockerfile, rebuild your image and try rerunning your application.
If you still face issues, add more verbose logging to your build process to gather more information. You can use the –loglevel verbose flag for npm during installation or other operations.
I hope one of these solutions will work for you!
Related posts
[nodemon] app crashed – waiting for file changes before starting
zsh: command not found: nodemon

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.