Reputation: 143
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
Upvotes: 13
Views: 13315
Reputation: 1
Check your dockerignore file once, I added package*.json
in dockerignore file, that's why it wasn't able to find the file.
Upvotes: 0
Reputation: 392
For me the package-lock.json
was a dead symlink, pointing to a non-existent file. When the builder resolved the symlink, the hash could not be computed because the file did not exist. Updating the symlink to reference the correct file solved the issue
Upvotes: 0
Reputation: 2413
I got the same error when i set Dockerfile and package.json in the same file, for me it was solved by adding "**/" to the path of the json file like this
FROM node:14.17.3-alpine AS build
WORKDIR /usr/src/app
COPY **/package.json **/package-lock.json ./
...
Upvotes: 7
Reputation: 41
check the path of package.json, note the package.json relative to the dockerfile's path
Upvotes: 4
Reputation: 25457
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.
Upvotes: 17