How to solve the error in package.json when creating an image?

Viewed 4423

In the step 4/6 is showing up an error when I try to create this image in Docker:

FROM node:latest

RUN mkdir -p /app/src

WORKDIR /app/src

COPY package.json .

RUN npm install
#IT WILL COPY THE ENTIRE DIR FORECAST TO /app/src INSIDE DOCKER
COPY . .

EXPOSE 3000

CMD {"npm",  "start"}

the error that shows is:

=> ERROR [4/6] COPY package.json .                                                                                0.0s
------
 > [4/6] COPY package.json .:
------
failed to compute cache key: "/package.json" not found: not found
3 Answers

I was getting a similar error.

failed to compute cache key: "/package.json" not found: not found

For me I included a .dockerignore file and placed many other entries other than node_modules

**/node_modules
README.md
package.json
package-lock.json
docker-compose.dev.yml

So naturally, its not copying required package.json file, and hence the error. Silly mistake from my side, hope this helps someone.

You can try:

COPY ["package*.json","./"]

check the path of package.json, note the package.json relative to the dockerfile's path

Related