-
-
Notifications
You must be signed in to change notification settings - Fork 61
Fixes #79 Resolved ERR_MODULE_NOT_FOUND during Vitest ESM resolution by adding explicit .js extensions to ESM imports. #106
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
Open
ankitrraj
wants to merge
6
commits into
StabilityNexus:main
Choose a base branch
from
ankitrraj:fix/wallet-component-esm-imports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b11dc0
docs: Add fix documentation and script for wallet-svelte-component ES…
ankitrraj 3d94563
docs: Add step-by-step guide for fixing wallet-svelte-component upstream
ankitrraj 3f749f6
docs: Add comprehensive summary of ESM fix work
ankitrraj d344c71
fix: Handle mixed quote styles in import statements
ankitrraj a988636
docs: Remove verbose documentation files
ankitrraj ff13137
fixed
ankitrraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| # Next Steps: Fixing wallet-svelte-component ESM Import Issue | ||
|
|
||
| ## Current Status ✅ | ||
|
|
||
| **Branch created:** `fix/wallet-component-esm-imports` | ||
|
|
||
| You're currently on this branch with the following files: | ||
| - `WALLET_COMPONENT_FIX.md` - Detailed documentation of the issue and fix | ||
| - `fix-imports-script.mjs` - Automated script to fix imports | ||
|
|
||
| ## What Has Been Done | ||
|
|
||
| 1. ✅ Created branch `fix/wallet-component-esm-imports` | ||
| 2. ✅ Documented the ESM import issue | ||
| 3. ✅ Created automated fix script | ||
| 4. ✅ Tested the fix locally (it works!) | ||
| 5. ✅ Committed the documentation | ||
|
|
||
| ## What You Need to Do Next | ||
|
|
||
| Since the issue is in the upstream `wallet-svelte-component` library, you need to fork and fix it separately: | ||
|
|
||
| ### Step 1: Fork wallet-svelte-component Repository | ||
|
|
||
| 1. Go to: https://github.com/ergo-basics/wallet-svelte-component | ||
| 2. Click "Fork" button (top right) | ||
| 3. This creates a fork under your account: `https://github.com/ankitrraj/wallet-svelte-component` | ||
|
|
||
| ### Step 2: Clone Your Fork | ||
|
|
||
| ```bash | ||
| cd C:\Users\ANRIT\Desktop | ||
| git clone https://github.com/ankitrraj/wallet-svelte-component.git | ||
| cd wallet-svelte-component | ||
| ``` | ||
|
|
||
| ### Step 3: Create a Branch for the Fix | ||
|
|
||
| ```bash | ||
| git checkout -b fix/add-js-extensions-to-esm-imports | ||
| ``` | ||
|
|
||
| ### Step 4: Copy the Fix Script | ||
|
|
||
| Copy the `fix-imports-script.mjs` from BenefactionPlatform-Ergo to wallet-svelte-component: | ||
|
|
||
| ```bash | ||
| Copy-Item ..\BenefactionPlatform-Ergo\fix-imports-script.mjs .\scripts\fix-imports.mjs | ||
| ``` | ||
|
|
||
| ### Step 5: Update package.json | ||
|
|
||
| Edit `package.json` in wallet-svelte-component and update the build scripts: | ||
|
|
||
| ```json | ||
| { | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "package": "svelte-package && node scripts/fix-imports.mjs dist", | ||
| "prepare": "svelte-package && node scripts/fix-imports.mjs dist" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Step 6: Create scripts Directory | ||
|
|
||
| ```bash | ||
| mkdir scripts | ||
| ``` | ||
|
|
||
| Then move the fix script into it. | ||
|
|
||
| ### Step 7: Test the Build | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm run package | ||
| # Check that dist/index.js has .js extensions | ||
| cat dist/index.js | Select-String "from './" | ||
| ``` | ||
|
|
||
| You should see all imports with `.js` extensions like: | ||
| ```javascript | ||
| export * from './wallet/wallet-manager.js'; | ||
| ``` | ||
|
|
||
| ### Step 8: Commit and Push | ||
|
|
||
| ```bash | ||
| git add . | ||
| git commit -m "fix: Add .js extensions to ESM imports for strict Node.js compatibility | ||
|
|
||
| Fixes module resolution errors in strict ESM environments (Vitest, etc.) | ||
| by ensuring all relative imports in the build output include .js file extensions. | ||
|
|
||
| Changes: | ||
| - Added post-build script to automatically fix import paths | ||
| - Updated package.json to run the fix script after svelte-package | ||
| - Ensures compatibility with Node.js when type: 'module' is set | ||
|
|
||
| Resolves: ERR_MODULE_NOT_FOUND errors in consuming projects" | ||
|
|
||
| git push origin fix/add-js-extensions-to-esm-imports | ||
| ``` | ||
|
|
||
| ### Step 9: Create Pull Request | ||
|
|
||
| 1. Go to your fork: `https://github.com/ankitrraj/wallet-svelte-component` | ||
| 2. Click "Pull Requests" → "New Pull Request" | ||
| 3. Select: | ||
| - **base repository:** `ergo-basics/wallet-svelte-component` | ||
| - **base branch:** `main` (or whatever their default is) | ||
| - **head repository:** `ankitrraj/wallet-svelte-component` | ||
| - **compare branch:** `fix/add-js-extensions-to-esm-imports` | ||
| 4. Title: **"fix: Add .js extensions to ESM imports for strict Node.js compatibility"** | ||
| 5. Description: Use the content from `WALLET_COMPONENT_FIX.md` sections | ||
|
|
||
| ### Step 10: Update BenefactionPlatform-Ergo Temporarily | ||
|
|
||
| While waiting for the PR to be merged, you can use your fork: | ||
|
|
||
| ```bash | ||
| cd C:\Users\ANRIT\Desktop\BenefactionPlatform-Ergo | ||
| ``` | ||
|
|
||
| Edit `package.json` and change: | ||
| ```json | ||
| { | ||
| "dependencies": { | ||
| "wallet-svelte-component": "github:ankitrraj/wallet-svelte-component#fix/add-js-extensions-to-esm-imports" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Then: | ||
| ```bash | ||
| npm install | ||
| npm test # Verify it works | ||
| ``` | ||
|
|
||
| ## Alternative: Quick Local Fix | ||
|
|
||
| If you just want to fix it locally without a PR right now, you can run: | ||
|
|
||
| ```bash | ||
| node fix-imports-script.mjs | ||
| ``` | ||
|
|
||
| This will patch your local `node_modules/wallet-svelte-component` but will be lost on next `npm install`. | ||
|
|
||
| ## Questions? | ||
|
|
||
| Check `WALLET_COMPONENT_FIX.md` for detailed explanations of: | ||
| - The root cause of the issue | ||
| - Why .js extensions are required in ESM | ||
| - Alternative fix approaches | ||
| - Testing instructions | ||
|
|
||
| ## Current Git Status | ||
|
|
||
| ```bash | ||
| # In BenefactionPlatform-Ergo | ||
| git branch | ||
| # * fix/wallet-component-esm-imports | ||
|
|
||
| git log -1 --oneline | ||
| # 2b11dc0 docs: Add fix documentation and script for wallet-svelte-component ESM import issue | ||
| ``` | ||
|
|
||
| Ready to push to origin and create a PR when the wallet-svelte-component fix is ready! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| # Wallet Svelte Component ESM Fix - Summary | ||
|
|
||
| ## ✅ What We've Accomplished | ||
|
|
||
| ### 1. Branch Created | ||
| - **Branch name:** `fix/wallet-component-esm-imports` | ||
| - **Status:** Local commits ready, needs to be pushed | ||
|
|
||
| ### 2. Problem Identified | ||
| The `wallet-svelte-component` package has missing `.js` file extensions on relative imports in its distribution files, causing `ERR_MODULE_NOT_FOUND` errors in strict ESM environments like Vitest. | ||
|
|
||
| **Example of the problem:** | ||
| ```javascript | ||
| // ❌ Before (in dist/index.js) | ||
| export * from './wallet/wallet-manager'; | ||
|
|
||
| // ✅ After fix | ||
| export * from './wallet/wallet-manager.js'; | ||
| ``` | ||
|
|
||
| ### 3. Solution Created | ||
| We've created two key files: | ||
|
|
||
| #### `fix-imports-script.mjs` | ||
| - Automated script that adds `.js` extensions to all ESM imports | ||
| - Successfully tested locally - fixed 8 imports across 4 files | ||
| - Can be used as a post-build step in the upstream repo | ||
|
|
||
| #### `WALLET_COMPONENT_FIX.md` | ||
| - Comprehensive documentation of the issue | ||
| - Step-by-step fix instructions | ||
| - Testing guidelines | ||
| - References to ESM best practices | ||
|
|
||
| #### `NEXT_STEPS.md` | ||
| - Clear guide on what to do next | ||
| - Instructions for forking and fixing wallet-svelte-component | ||
| - How to create a PR to the upstream repo | ||
|
|
||
| ### 4. Local Testing | ||
| ✅ Script successfully fixed imports in `node_modules/wallet-svelte-component/dist/` | ||
| ✅ Tests run without ESM module resolution errors | ||
|
|
||
| ## 📋 Current Git Status | ||
|
|
||
| ```bash | ||
| Branch: fix/wallet-component-esm-imports | ||
| Commits: 2 | ||
| - 2b11dc0 docs: Add fix documentation and script for wallet-svelte-component ESM import issue | ||
| - 3d94563 docs: Add step-by-step guide for fixing wallet-svelte-component upstream | ||
|
|
||
| Status: Ready to push (needs GitHub authentication) | ||
| ``` | ||
|
|
||
| ## 🚀 Next Actions Required | ||
|
|
||
| ### Immediate: Push This Branch | ||
|
|
||
| **Issue:** Git push failed due to authentication using wrong credentials (DevStudio instead of ankitrraj) | ||
|
|
||
| **Solutions:** | ||
| 1. **Use GitHub CLI (Recommended):** | ||
| ```bash | ||
| gh auth login | ||
| git push -u origin fix/wallet-component-esm-imports | ||
| ``` | ||
|
|
||
| 2. **Use Personal Access Token:** | ||
| ```bash | ||
| # Go to https://github.com/settings/tokens | ||
| # Generate a new token with 'repo' scope | ||
| # Then push using: | ||
| git push https://ankitrraj:<YOUR_TOKEN>@github.com/ankitrraj/BenefactionPlatform-Ergo.git fix/wallet-component-esm-imports | ||
| ``` | ||
|
|
||
| 3. **Update Git Credentials:** | ||
| ```bash | ||
| git config --global credential.helper wincred | ||
| git push -u origin fix/wallet-component-esm-imports | ||
| # Windows will prompt for credentials | ||
| ``` | ||
|
|
||
| ### Then: Fork and Fix Upstream | ||
|
|
||
| Follow the detailed steps in `NEXT_STEPS.md`: | ||
|
|
||
| 1. Fork `ergo-basics/wallet-svelte-component` on GitHub | ||
| 2. Clone your fork locally | ||
| 3. Apply the fix using `fix-imports-script.mjs` | ||
| 4. Update build configuration | ||
| 5. Test the fix | ||
| 6. Create PR to upstream repository | ||
|
|
||
| ### Finally: Update BenefactionPlatform-Ergo | ||
|
|
||
| Once your fork is ready, update `package.json`: | ||
| ```json | ||
| { | ||
| "dependencies": { | ||
| "wallet-svelte-component": "github:ankitrraj/wallet-svelte-component#fix/add-js-extensions-to-esm-imports" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## 📁 Files Created in This Branch | ||
|
|
||
| ``` | ||
| BenefactionPlatform-Ergo/ | ||
| ├── WALLET_COMPONENT_FIX.md # Detailed problem analysis and fix guide | ||
| ├── fix-imports-script.mjs # Automated fix script (tested ✅) | ||
| ├── NEXT_STEPS.md # Step-by-step action guide | ||
| └── SUMMARY.md # This file | ||
| ``` | ||
|
|
||
| ## 🎯 The Issue to Be Fixed Upstream | ||
|
|
||
| **Repository:** https://github.com/ergo-basics/wallet-svelte-component | ||
| **Issue:** Missing .js extensions in ESM imports | ||
| **Impact:** Breaks in strict Node.js ESM environments (Vitest, etc.) | ||
| **Fix:** Add post-build script to append .js extensions | ||
| **Effort:** Low (script already created and tested) | ||
|
|
||
| ## 💡 Why This Matters | ||
|
|
||
| Modern JavaScript with `"type": "module"` in package.json requires explicit file extensions for relative imports. Without them: | ||
| - ❌ Vitest tests fail with ERR_MODULE_NOT_FOUND | ||
| - ❌ Cannot use in projects with strict ESM mode | ||
| - ❌ Breaks Node.js best practices for ESM | ||
|
|
||
| With the fix: | ||
| - ✅ Full compatibility with ESM environments | ||
| - ✅ Tests run successfully | ||
| - ✅ Follows Node.js ESM specifications | ||
|
|
||
| ## 📞 Need Help? | ||
|
|
||
| Check these files for more details: | ||
| - **Problem details:** `WALLET_COMPONENT_FIX.md` | ||
| - **What to do next:** `NEXT_STEPS.md` | ||
| - **Auto-fix script:** `fix-imports-script.mjs` | ||
|
|
||
| --- | ||
|
|
||
| **Status:** 🟡 Waiting for GitHub authentication to push branch | ||
| **Next Step:** Authenticate and push, then follow NEXT_STEPS.md |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add language identifier to fenced code block.
The code block at line 107 is missing a language identifier, which affects syntax highlighting and accessibility tools.
As per static analysis hints, apply this diff:
In NEXT_STEPS.md around lines 107 to 117 the fenced code block is missing a
language identifier which prevents proper syntax highlighting; update the
opening fence to include the language (e.g., change "
" to "bash") andensure the matching closing fence remains present so the block renders correctly
and accessibility/syntax tools recognize it.