Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jan 29, 2026

Fixes #6353.

When using base_dir with no_bundle = true and a nested entry point (e.g., main = "./some/base_dir/nested/index.js" with base_dir = "./some/base_dir"), relative imports like ../foo.js would fail with "internal error" because Miniflare's modulesRoot was incorrectly set to the entry point's directory instead of the configured base_dir.

The fix conditionally sets modulesRoot in buildSourceOptions():

  • When the script path is within entry.moduleRoot (e.g., no_bundle with base_dir), use entry.moduleRoot
  • Otherwise, fall back to path.dirname(scriptPath) (e.g., bundled output in temp directory)

This conditional approach ensures the fix only applies to the no_bundle case and doesn't break normal bundling where the output is in a temp directory outside moduleRoot.

Key review points:

  • The entry.moduleRoot is already computed correctly in entry.ts (line 160-161) based on base_dir or defaults to path.dirname(entry.file), so this change should be safe for workers without base_dir
  • The new test simulates the exact scenario from the issue: nested entry point importing a module from the parent directory
  • The existing "should start Miniflare with module worker" test was updated to have module names consistent with moduleRoot (e.g., name: "esm/add.cjs" with filePath: "/virtual/esm/add.cjs" instead of inconsistent paths)

Human review checklist:

  • Verify entry.moduleRoot is always correctly populated in all code paths
  • Confirm the conditional path prefix check handles edge cases (e.g., similar path prefixes, Windows vs Unix separators)
  • Confirm the existing test updates don't mask any regressions (the old test had inconsistent module name/filePath which happened to work with the old path.dirname(scriptPath) behavior)

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This is a bug fix for existing functionality

Devin PR requested by lrapoport@cloudflare.com

Link to Devin run: https://app.devin.ai/sessions/47e122404e334bb19ec20b6e19efedb5

…ase_dir

Co-Authored-By: lrapoport@cloudflare.com <lrapoport@cloudflare.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest 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-integration
Copy link
Contributor Author

🤖 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 that start with 'DevinAI' or '@devin'.
  • 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

@claude
Copy link
Contributor

claude bot commented Jan 29, 2026

Claude finished @devin-ai-integration[bot]'s task —— View job


Changeset Review

  • Read changeset guidelines
  • Read changeset file
  • Validate changeset
  • Report findings

✅ All changesets look good

The changeset at .changeset/fix-base-dir-modules-root.md is well-formatted:

  • Version type: patch is correct for a bug fix
  • Description: Clear and detailed explanation of what was broken and what was fixed
  • Markdown headers: No h1/h2/h3 headers present
  • Format: Follows the recommended single-sentence title + explanatory body format

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 29, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12272

wrangler

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

commit: d818b6d

devin-ai-integration bot and others added 2 commits January 29, 2026 15:22
Co-Authored-By: lrapoport@cloudflare.com <lrapoport@cloudflare.com>
Co-Authored-By: lrapoport@cloudflare.com <lrapoport@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

🐛 BUG: relative imports from a nested main in base_dir breaks

0 participants