Docker: npm not found
26,485
Solution 1
Try installing npm
separately while building the image:
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y nodejs \
npm # note this one
Solution 2
Node
also packages npm
, so no need to install npm
like mentioned by Yury. It's in general a bad idea to do it like that, because you don't have control over the nodejs
and npm
version
For me the answer was quite simple. I had the following code:
# install nodejs
RUN curl --silent --location https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y \
nodejs
RUN echo "Node: " && node -v
RUN echo "NPM: " && npm -v
but I for got to install curl, so it failed. So before this, you need to install curl:
RUN apt-get update && apt-get install -y curl
![Sohrab](https://i.stack.imgur.com/NOmKt.png?s=256&g=1)
Author by
Sohrab
Updated on July 05, 2022Comments
-
Sohrab almost 2 years
I have the following Dockerfile:
FROM ubuntu USER root RUN apt-get update && apt-get install curl -y RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - RUN apt-get update && apt-get upgrade -y && apt-get install nodejs -y RUN mkdir /opt/public RUN mkdir /opt/bin ADD public /opt/public ADD bin /opt/bin RUN ls -lah /opt/bin RUN ls -lah /opt/public ADD run.sh /bin/run.sh RUN chmod +x /bin/run.sh RUN cd /opt/bin && npm install CMD ["/bin/run.sh"]
When I build the Container, I get this eror:
/bin/sh: 1: npm: not found
What is the problem? Could you please help me?
-
Sohrab over 5 yearsThanks, I used "apt-get install npm -y" instead of "npm install". Everything is ok.
-
Sohrab over 5 yearsWhen I run docker, I get this error: Cannot find module 'localstorage-polyfill' Do you have any solution?
-
Yury Fedorov over 5 yearsIt's probably because you cnahged
npm install
toapt-get install npm
, while you need both -
Sohrab over 5 yearsYou are right. I wrote both in the Dockerfile. Everything is fine.
-
fabpico over 4 yearsDid not work for me, i had to
curl -sL https://deb.nodesource.com/setup_13.x | bash -
first. -
bersling over 3 years@FabianPicone I also prefer that option, but don't forget to install curl, or you'll get exactly the error outlined above :)
-
tplusk about 3 yearsGreat catch! I had the same gotcha