Skip to content

fix: normalize Windows paths in copyWorkerdPackages so serverExternalPackages match#1268

Open
ton11797 wants to merge 1 commit into
opennextjs:mainfrom
ton11797:fix/workerd-copy-windows-paths
Open

fix: normalize Windows paths in copyWorkerdPackages so serverExternalPackages match#1268
ton11797 wants to merge 1 commit into
opennextjs:mainfrom
ton11797:fix/workerd-copy-windows-paths

Conversation

@ton11797
Copy link
Copy Markdown

@ton11797 ton11797 commented May 16, 2026

Problem #661

On Windows, packages listed in serverExternalPackages were silently dropped from the workerd-condition copy step, leaving their web.mjs / web.cjs files absent from
the bundle. The downstream esbuild then fails with Could not resolve "" and a message that ./web.mjs was not found.

Concrete repro: a Next.js app on Windows using @libsql/client with serverExternalPackages: ["@libsql/isomorphic-ws"] will fail opennextjs-cloudflare build because @libsql/isomorphic-ws declares "workerd": "./web.mjs" in its exports but only node.cjs/node.mjs/package.json get copied.

Cause

copyWorkerdPackages extracted the package name with src.match(/./node_modules/(?.)/) (cross-platform via getCrossPlatformPathRegex). The regex matched, but the captured pkg group retained the path's native separator. On Windows the captured value was @libsql\isomorphic-ws, which never matched the forward-slash entry in serverExternalPackages, so the workerd-copy was skipped.

Fix

Extracted a small helper that:

  • normalizes \ → / on the captured group, and
  • trims trailing subpath, so nested package.json files (e.g. @scope/pkg/lib-cjs/package.json) resolve back to @scope/pkg rather than @scope/pkg/lib-cjs.

Tests

Added unit tests for the helper covering POSIX/Windows × scoped/unscoped/subpath, plus a non-node_modules negative case.


Open in Devin Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 16, 2026

🦋 Changeset detected

Latest commit: eb874f9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@1268

commit: eb874f9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant