Dockerfile “failed to solve: cannot copy to non-directory”

I have a Dockerfile in my frontend folder with the following code:

FROM node:20-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app
COPY package*.json ./
RUN pnpm install
COPY . .

# EXPOSE 3000
CMD ["pnpm", "dev"]

When running docker build -t frontend . , I get the following error: “ERROR: failed to solve: cannot copy to non-directory: /var/lib/docker/overlay2/mui7qp60yzb3ibzhtv7dga6l2/merged/app/node_modules/@eslint/eslintrc“.

I even added a .dockerignore file with the following lines:

node_modules/
.git
.gitignore
*.md
dist

I have tried running pnpm install to reinstall packages, delete all images and rerun docker with no cache. I am not sure how to resolve this issue.