Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

package.json not found in docker

I have a problem.
Build project in docker and have error. That docker on npm install not found ppackage.json

Dockerfile

FROM node

#copy source
COPY . /app

# Install deps
RUN cd /app && npm install

# Build
CMD npm run build

CMD [ "npm", "run", "start" ]

BUT IN DOCKER PACKAGE.JSON EXIST

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

npm ERR! code ENOENT
2023-07-16T10:00:25.897789910Z npm ERR! syscall open
2023-07-16T10:00:25.898344831Z npm ERR! path /package.json
2023-07-16T10:00:25.899843841Z npm ERR! errno -2
2023-07-16T10:00:25.901767270Z npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/package.json'
2023-07-16T10:00:25.901968559Z npm ERR! enoent This is related to npm not being able to find a file.
2023-07-16T10:00:25.902319000Z npm ERR! enoent 
2023-07-16T10:00:25.904753122Z 
2023-07-16T10:00:25.904888750Z npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-07-16T10_00_25_792Z-debug-0.log
2023-07-16T10:00:25.934642675Z 
  • Delete packagae-lock.json
  • Rebuild container

>Solution :

I guess you need to change the cd into WORKDIR

add WORKDIR "/app"

and you have 2 CMD commands, which will only execute the latter one.

Am not quite sure, but I guess your Dockerfile should look like this

FROM node

COPY . /app

WORKDIR "/app"

RUN npm install
RUN npm run build


CMD [ "npm", "run", "start" ]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading