Skip to content

fix: respect TypeScript path aliases when resolving non-JS modules with module rules#11649

Merged
ascorbic merged 1 commit intomainfrom
devin/1765816088-fix-tsconfig-paths-module-collection
Dec 16, 2025
Merged

fix: respect TypeScript path aliases when resolving non-JS modules with module rules#11649
ascorbic merged 1 commit intomainfrom
devin/1765816088-fix-tsconfig-paths-module-collection

Conversation

@ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Dec 15, 2025

Fixes #2954.

Devin PR requested by @ascorbic

When importing non-JavaScript files (like .graphql, .txt, etc.) using TypeScript path aliases defined in tsconfig.json, Wrangler's module-collection plugin was not correctly resolving these imports. This was because the build.resolve() call was using a hard-coded kind: "import-statement" without passing the importer context, which prevented esbuild from applying the tsconfig path mappings.

The fix passes args.kind and args.importer to build.resolve(), allowing esbuild to properly resolve path aliases for non-JS modules.

Example that now works:

// tsconfig.json: { "compilerOptions": { "paths": { "~lib/*": ["lib/*"] } } }
// wrangler.toml: rules = [{ type = "Text", globs = ["**/*.graphql"] }]
import schema from '~lib/schema.graphql';


Human Review Checklist:

  • Verify passing args.kind and args.importer doesn't break existing non-aliased module resolution
  • Confirm the test correctly validates the fix (uses deterministic SHA1 hash of file content for module name)

Link to Devin run: https://app.devin.ai/sessions/359225f1b8cc46d5a846f1dbd6dcfd26

…th module rules

When importing non-JavaScript files (like .graphql, .txt, etc.) using TypeScript
path aliases defined in tsconfig.json, Wrangler's module-collection plugin now
correctly resolves these imports by passing the importer context to esbuild's
build.resolve() function.

Fixes #2954

Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: 495c60d

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-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 15, 2025
@ascorbic ascorbic marked this pull request as ready for review December 16, 2025 10:03
@ascorbic ascorbic requested a review from a team as a code owner December 16, 2025 10:03
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Dec 16, 2025
@ascorbic ascorbic merged commit 428ae9e into main Dec 16, 2025
44 of 51 checks passed
@ascorbic ascorbic deleted the devin/1765816088-fix-tsconfig-paths-module-collection branch December 16, 2025 14:12
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Dec 16, 2025
AmirSa12 pushed a commit to AmirSa12/workers-sdk that referenced this pull request Jan 5, 2026
…th module rules (cloudflare#11649)

When importing non-JavaScript files (like .graphql, .txt, etc.) using TypeScript
path aliases defined in tsconfig.json, Wrangler's module-collection plugin now
correctly resolves these imports by passing the importer context to esbuild's
build.resolve() function.

Fixes cloudflare#2954

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Respect TypeScript path aliases in Wrangler module-collection

2 participants