-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Add .js extension to dynamic imports in ES modules #1
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?
Conversation
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>
WalkthroughThe 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
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
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
.jsextensions 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`)orimport("./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
📒 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
.jsextensions 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
.jsextension to the dynamic import path correctly resolves ES module resolution for the worktree lifecycle helper.
Summary
Fixes ERR_MODULE_NOT_FOUND errors when creating worktrees by adding
.jsextensions to dynamicimports.
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:
.jsextensionsSolution
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