fix(docker): filter nested node_modules/dist in .dockerignore#54
fix(docker): filter nested node_modules/dist in .dockerignore#54
Conversation
…s/dist
Before this fix, `.dockerignore` patterns `node_modules` and `dist` only
matched the build-context root, not nested directories. That meant any
host-side `pnpm install` in `packages/*/` (e.g. from running `next dev`
locally in `packages/demo/`) left a `packages/demo/node_modules/` tree
that got copied into the Docker build context by `COPY packages/ .../`,
overwriting the fresh pnpm symlink tree that the `deps` stage had just
created inside the image.
The host's symlinks pointed to host paths (`/app/node_modules/.pnpm/...`)
that don't exist inside the image, so `pnpm run build` failed with:
Cannot find module '/app/packages/demo/node_modules/next/dist/bin/next'
Using `**/node_modules` (and `**/dist`) makes the patterns match at any
depth, filtering every nested node_modules/dist out of the build context
as originally intended. Verified by building Dockerfile.auth,
Dockerfile.demo, and Dockerfile.pds from scratch with `--no-cache` in a
working tree that had a populated `packages/demo/node_modules/`; all
three now succeed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚅 Deployed to the ePDS-pr-54 environment in ePDS
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Coverage Report for CI Build 24142550619Coverage remained the same at 29.583%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |



Summary
.dockerignorepatternsnode_modulesanddistonly matched the build-context root, so any host-sidepackages/*/node_modulesorpackages/*/distleaked into the Docker build context.node_modulesdirs were copied into the image byCOPY packages/ packages/, overwriting the pnpm symlink tree thedepsstage had just created. The host symlinks pointed to host paths that don't exist inside the image, sopnpm run buildfailed with e.g.Cannot find module '/app/packages/demo/node_modules/next/dist/bin/next'.**/globs makes the filters match at any depth, which is what was originally intended.Why this only bites some users
If you've ever run
pnpm install(ornext dev) locally insidepackages/demo/— easy to do when iterating on the demo app — you end up with a populatedpackages/demo/node_modules/on disk. Clean CI environments and fresh clones don't have that, so they never hit the bug. That's whydocker buildworks on CI but fails on dev laptops that have also been used to run the app locally.Verification
Built all three images from scratch with
--no-cachein a working tree that had a populatedpackages/demo/node_modules/(reproducing the original failure), applied this one-line fix, and reran:Dockerfile.demoCannot find module '/app/packages/demo/node_modules/next/dist/bin/next'Dockerfile.pdsDockerfile.authAlso confirmed via an inspection image (
alpine + COPY . /ctx/ + find /ctx -name node_modules) that after the fix, zero nestednode_modulesdirectories leak into the build context (before: everypackages/*/node_modulesplus any.claude/worktrees/*/node_moduleswas leaking).Test plan
docker build -f Dockerfile.demo .on a machine that haspackages/demo/node_modules/populated locally — should succeed.docker build -f Dockerfile.auth .anddocker build -f Dockerfile.pds .— should still succeed (they never broke, just verifying no regression).🤖 Generated with Claude Code
Summary by CodeRabbit