Docker build fails at npm install
As mentioned in the comment, add a step in the docker file to copy the package-lock.json
file over to the destination.
The reason why it works on your local machine is because package-lock.json
tells npm exactly which versions to install. For example, Typescript
is listed as ^4.1.3
in package.json
. In your local machine, it could have been installed as exactly 4.1.3
(check your package-lock.json
) file. However, in the production machine, it might have installed version 4.2.1
or something. So even though you listed 4.1.3
, it actually pulls in a higher version because of the ^
prefix, which means you are good with having higher minor and patch versions installed. Therefore, you might be expecting 4.1.3
or whatever version it is on your local machine, the production server might have installed a much newer version because it did not refer to the package-lock.json
file that's created in your local machine.
Check out what ^
and ~
means here in this answer - What's the difference between tilde(~) and caret(^) in package.json?