Skip to content

Conversation

@afterthought
Copy link

@afterthought afterthought commented Oct 23, 2025

Summary

Fixes ERR_MODULE_NOT_FOUND errors when creating worktrees by adding .js extensions to dynamic
imports.

Problem

The package was failing at runtime with:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/path/to/git-worktree-toolbox/dist/utils/git'
imported from /path/to/git-worktree-toolbox/dist/worktree/metadata.js

This occurred because:

  1. ES modules require explicit file extensions in import statements
  2. The build script only fixed static imports, not dynamic imports
  3. Dynamic imports were left without .js extensions

Solution

  • Fixed 3 dynamic imports in source files
  • Enhanced build script to handle dynamic imports automatically

Testing

✅ Successfully builds
✅ Worktree creation works
✅ Metadata generation works

This fixes a critical bug preventing metadata tracking from working in v0.4.0.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed dynamic import resolution to ensure modules load correctly with proper file extensions.

Fixed ERR_MODULE_NOT_FOUND errors when creating worktrees by:
- Adding .js extensions to dynamic imports in source files
- Updating fix-imports.js script to handle dynamic imports

Previously, the build script only fixed static import statements,
leaving dynamic imports without the required .js extension for ES modules.
This caused module resolution failures at runtime when creating worktrees.

Changes:
- src/tools/worktree-lifecycle.ts: Added .js to gitDiffStats imports
- src/tools/worktree-changes.ts: Added .js to ensureWorktreeHasMetadata import
- scripts/fix-imports.js: Added regex patterns to fix dynamic imports during build

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2025

Walkthrough

The pull request standardizes dynamic import paths across the codebase by appending .js file extensions. A script is enhanced with two new replacement rules for dynamic imports missing extensions, and two TypeScript files have their import statements updated to explicitly include the .js file extension for proper module resolution.

Changes

Cohort / File(s) Summary
Import path normalization script
scripts/fix-imports.js
Added two new regex replacements to append .js extension to dynamic imports with ../ and ./ paths missing the extension
TypeScript tool files
src/tools/worktree-changes.ts, src/tools/worktree-lifecycle.ts
Updated dynamic import paths to include .js extensions: "./worktree-lifecycle" → "./worktree-lifecycle.js" and "@/src/utils/git" → "@/src/utils/git.js"

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes are homogeneous import path standardizations with consistent patterns across files. No complex logic modifications or control flow changes are present. Review focuses on verifying correct path mappings and regex replacement patterns.

Poem

🐰 Imports need their proper dress,
With .js, they pass the test!
Extensions bright, extensions clear,
Module paths are crisp and dear!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix: Add .js extension to dynamic imports in ES modules" accurately and specifically summarizes the main changes across all modified files. The title clearly identifies both the action taken (adding .js extensions) and the target (dynamic imports in ES modules), which aligns with the changes in scripts/fix-imports.js (enhanced build script), src/tools/worktree-changes.ts (import path update), and src/tools/worktree-lifecycle.ts (multiple import path updates). The title is concise, avoids vague terminology, and directly addresses the primary objective of fixing runtime module resolution failures. A team member reviewing the repository history would immediately understand that this PR resolves issues related to missing file extensions in ES module dynamic imports.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
scripts/fix-imports.js (1)

20-28: Good automation to prevent future issues.

The new replacement rules correctly handle dynamic imports with relative paths, adding .js extensions where missing. The negative lookbehind ensures idempotency.

For completeness, consider edge cases like template literals or dynamic expressions in import paths (e.g., import(`./path`) or import("./base" + path)). However, these are uncommon and the current implementation handles the standard cases well.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c16b23c and a55a250.

📒 Files selected for processing (3)
  • scripts/fix-imports.js (1 hunks)
  • src/tools/worktree-changes.ts (1 hunks)
  • src/tools/worktree-lifecycle.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/tools/worktree-lifecycle.ts (1)
src/utils/git.ts (1)
  • gitDiffStats (368-410)
🔇 Additional comments (2)
src/tools/worktree-lifecycle.ts (1)

600-623: LGTM! Dynamic imports correctly fixed.

The addition of .js extensions to both dynamic imports correctly addresses the ES module requirement and resolves the runtime ERR_MODULE_NOT_FOUND error mentioned in the PR objectives.

src/tools/worktree-changes.ts (1)

86-88: LGTM! Dynamic import path correctly updated.

The addition of .js extension to the dynamic import path correctly resolves ES module resolution for the worktree lifecycle helper.

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