Skip to content

Improve error message when modules cannot be resolved during bundling#12931

Open
dario-piotrowicz wants to merge 5 commits intomainfrom
dario/7095/suggest-alias
Open

Improve error message when modules cannot be resolved during bundling#12931
dario-piotrowicz wants to merge 5 commits intomainfrom
dario/7095/suggest-alias

Conversation

@dario-piotrowicz
Copy link
Member

@dario-piotrowicz dario-piotrowicz commented Mar 16, 2026

Fixes #7095

When a module cannot be resolved during bundling, Wrangler now suggests using the alias configuration option to substitute it with an alternative implementation. This replaces esbuild's default suggestion to "mark the path as external", which is not a supported option in Wrangler.


A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: 8e2b0ff

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

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

✅ All changesets look good

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 16, 2026

The handle-errors.ts path at lines 564-569 just logs the build failure errors - by the time execution reaches this code, the error has already been thrown from bundleWorker in bundle.ts where the rewrites happened. So the rewritten error messages will be properly displayed. Good.

Now let me review everything I've seen and assess:

Summary of changes:

  1. New rewriteUnresolvedModuleBuildFailure function in build-failures.ts that replaces esbuild's "mark as external" suggestion with a Wrangler-specific suggestion to use alias.
  2. The function is called in bundle.ts right after the existing rewriteNodeCompatBuildFailure.
  3. Tests in both BundleController.test.ts (dev path) and build.test.ts (deploy path).
  4. Changeset included.

Assessment:

  • The logic is correct: it matches Could not resolve "X" errors, skips Node builtins (handled by the other function), and only rewrites when esbuild's "mark as external" note is present.
  • The ordering of the two rewrite functions doesn't matter because rewriteUnresolvedModuleBuildFailure checks the error.text (which isn't modified by rewriteNodeCompatBuildFailure) to skip Node builtins.
  • Tests cover both the positive case (non-Node module) and the negative case (Node builtin) in both code paths.
  • The test patterns match the existing conventions in the file.
  • The changeset is properly formatted as a patch.
  • No security, backward compatibility, or logic issues found.

LGTM

github run

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 16, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12931

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12931

miniflare

npm i https://pkg.pr.new/miniflare@12931

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12931

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12931

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12931

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12931

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12931

wrangler

npm i https://pkg.pr.new/wrangler@12931

commit: 8e2b0ff

@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review March 16, 2026 23:54
@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner March 16, 2026 23:54
@workers-devprod
Copy link
Contributor

workers-devprod commented Mar 16, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Contributor

@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 2 additional findings.

Open in Devin Review

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Happy to have an improved error message here. I left a comment about the actual content of the message as I think we could be more concrete and helpful.

@dario-piotrowicz dario-piotrowicz force-pushed the dario/7095/suggest-alias branch from 0a6e0a1 to 53706b0 Compare March 18, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

🐛 BUG: You can mark the path <pathname> as external is not an actionable error message

3 participants