turbo: cannot copy to non-directory DOCKER MACOS

What version of Turborepo are you using?

1.4.7

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Mac

Describe the Bug

On Mac, I tested on windows and this run perfectly, with this repo: https://github.com/yovanoc/turbo-test

if we run pnpm build:docker this give:

image

Expected Behavior

Should work on Mac too

To Reproduce

Just clone the repo and build with docker

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 17
  • Comments: 29 (8 by maintainers)

Most upvoted comments

Try add **/node_modules to .dockerignore

Had the same issue. It was fixed by adding **/node_modules to .dockerignore, like @John-Hejzlar said.

I had this same issue & noticed that after running the prune command (even outside of Docker), each package in out/full had a node_modules with the expected file structure, but with no actual source code. I think everything that pnpm symlinked is just missing in the full pruned output, but the fact that the node_modules directory structure is there causes an issue? I was able to work around this by removing all node_modules from out/full – this is my full working Dockerfile:

FROM node:16-alpine AS builder
RUN apk update
# Set working directory
WORKDIR /app
RUN corepack enable
COPY . .
RUN pnpm --package=turbo dlx turbo prune --scope=web --docker

# remove all empty node_modules folder structure
RUN rm -rf /app/out/full/*/*/node_modules

# Add lockfile and package.json's of isolated subworkspace
FROM node:16-alpine AS installer
RUN apk update
RUN corepack enable
WORKDIR /app

# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install

# Build the project
COPY turbo.json turbo.json
COPY --from=builder /app/out/full/ .
RUN pnpm turbo run build --filter=web...

FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

# Automatically leverage output traces to reduce image size 
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./.next/static

CMD node apps/web/server.js

I’m not actually sure what the intention is with the prune command though – ie:, why does the with-docker example copy over just the pruned package jsons and lockfile before running pnpm install, and THEN copy over the full source code? Wouldn’t the pruned lockfile & package.json just be installing everything already in out/full anyway? Why not just copy over out/full and then run install (I guess it’s to do with Docker layer cacheing where the source code changes more frequently than the dependencies)?

Update to add full source code: https://github.com/redbadger/monorepo-examples/tree/turborepo-monobuild

I am having this issue as well. Also on a Mac (M1). Was not yet able to test on a Windows machine but will do. This is my (very similar) Dockerfile:

FROM node:alpine AS base
RUN apk update

# Globally install `turbo`
RUN yarn global add turbo

# Prune the workspace for the `tester` app
FROM base as pruner
WORKDIR /app
COPY . .
RUN turbo prune --scope=@wecoma-lite-tester/tester --docker

FROM base AS builder
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
COPY .npmrc .

# Install the deps needed to build the target
RUN corepack enable
RUN pnpm install

# Copy source code of pruned subworkspace and build
COPY --from=pruner /app/out/full/ .
COPY turbo.json turbo.json
RUN pnpm turbo run build --scope=@wecoma-lite-tester/tester...

And the error I get: Screenshot 2022-09-21 at 0 29 25

I already tested all mentioned fix ideas but nothing worked for me.

https://github.com/vercel/turbo/discussions/3346#discussioncomment-5703415

Yeah it’s the symlinks

(must include root node_modules - talking about docker-compose dev here)

encountered the same with WSL2 Ubuntu. **/node_modules fixed it for me

@xencodes I ran into the same thing, I think the example build assumes you’re using standalone output https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files

Try add **/node_modules to .dockerignore

Lifesaver!

If docker can’t copy ‘out’ dir of turbo during build and if you use M1 you can solve with this environment for docker DOCKER_DEFAULT_PLATFORM=linux/amd64

I had this issue too with just node_modules, but **/node_modules will ignore all node_modules.

Same here on Windows 11 > WSL2 (Ubuntu 22.10)

Wondering if it’s related to symlinks; what if you add node_modules to the .dockerignore file to avoid its including it as part of the build context? Especially when you say it works on Windows I think it could be symlinks related

@tknickman I’m tagging you in on this one; can reproduce, but seems quite strange to me.