-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[wrangler] Fix relative imports from nested entry points when using base_dir #12272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[wrangler] Fix relative imports from nested entry points when using base_dir #12272
Conversation
…ase_dir Co-Authored-By: lrapoport@cloudflare.com <lrapoport@cloudflare.com>
🦋 Changeset detectedLatest commit: d818b6d 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 |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Claude finished @devin-ai-integration[bot]'s task —— View job Changeset Review
✅ All changesets look good The changeset at
|
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Co-Authored-By: lrapoport@cloudflare.com <lrapoport@cloudflare.com>
Co-Authored-By: lrapoport@cloudflare.com <lrapoport@cloudflare.com>
Fixes #6353.
When using
base_dirwithno_bundle = trueand a nested entry point (e.g.,main = "./some/base_dir/nested/index.js"withbase_dir = "./some/base_dir"), relative imports like../foo.jswould fail with "internal error" because Miniflare'smodulesRootwas incorrectly set to the entry point's directory instead of the configuredbase_dir.The fix conditionally sets
modulesRootinbuildSourceOptions():entry.moduleRoot(e.g.,no_bundlewithbase_dir), useentry.moduleRootpath.dirname(scriptPath)(e.g., bundled output in temp directory)This conditional approach ensures the fix only applies to the
no_bundlecase and doesn't break normal bundling where the output is in a temp directory outsidemoduleRoot.Key review points:
entry.moduleRootis already computed correctly inentry.ts(line 160-161) based onbase_diror defaults topath.dirname(entry.file), so this change should be safe for workers withoutbase_dirmoduleRoot(e.g.,name: "esm/add.cjs"withfilePath: "/virtual/esm/add.cjs"instead of inconsistent paths)Human review checklist:
entry.moduleRootis always correctly populated in all code pathspath.dirname(scriptPath)behavior)Devin PR requested by lrapoport@cloudflare.com
Link to Devin run: https://app.devin.ai/sessions/47e122404e334bb19ec20b6e19efedb5