Date: 2024-12-19
Project: Gateway
Issue: Build failures due to version incompatibilities between wagmi 2.19.5 and viem 2.21.4
The build was failing due to multiple compatibility issues between @wagmi/core (via wagmi 2.19.5) and viem 2.21.4. The primary issue was that wagmi was attempting to import functions from viem/actions that either:
- Don't exist in that location (they're in
viem/experimental) - Don't exist at all in viem 2.21.4
- Exist but aren't exported from the main module
Status: ✅ Original getCapabilities error resolved. Additional compatibility issues identified and partially resolved.
Problem: @wagmi/core imports EIP-5792 functions from viem/actions, but they're actually in viem/experimental.
Affected Functions:
getCapabilities⚠️ Original errorgetCallsStatussendCallsshowCallsStatuswriteContracts
Solution: Created Vite transform plugin that redirects these imports to viem/experimental.
Files Modified:
vite.config.ts- Added transform logic inviemCompatibilityFixplugin
Problem: @wagmi/core imports functions that don't exist in viem 2.21.4.
Affected Functions:
sendCallsSyncsendTransactionSyncwaitForCallsStatusprepareAuthorization(from porto)
Solution: Created stub implementations that throw descriptive errors.
Files Created:
client/src/lib/viem-actions-sendCallsSync-stub.tsclient/src/lib/viem-actions-sendTransactionSync-stub.tsclient/src/lib/viem-actions-waitForCallsStatus-stub.tsclient/src/lib/viem-actions-prepareAuthorization-stub.ts
Files Modified:
vite.config.ts- Added stub mappings and transform logicvite.config.ts- Addedloadhook to intercept and modify files before parsing
Problem: Functions exist in viem but aren't exported from the main package entry point.
Affected Functions:
withCache- Exists inviem/utils/promise/withCachebut not exported via package exports
Solution: Created stub implementation and added alias mapping.
Files Created:
client/src/lib/viem-withCache-stub.ts
Files Modified:
vite.config.ts- Added alias forviem/utils/promise/withCachevite.config.ts- Added transform to redirect imports
Problem: viem/experimental/erc7821 doesn't exist in viem 2.21.4, but dependencies try to import from it.
Affected Functions:
getExecuteErrorencodeExecuteData
Solution: Enhanced existing stub to export these functions.
Files Modified:
client/src/lib/viem-erc7821-stub.ts- Added stub exports
Files Modified:
vite.config.ts- Already had alias mapping forviem/experimental/erc7821
Created a custom Vite plugin (viemCompatibilityFix) with:
-
resolveIdhook:- Redirects
viem/experimental/erc7821to stub file
- Redirects
-
loadhook:- Intercepts specific wagmi files before parsing
- Directly modifies import statements for stub functions
- Handles:
sendCallsSync.js,sendTransactionSync.js,waitForCallsStatus.js
-
transformhook:- Transforms imports from
viem/actionsto redirect experimental functions - Transforms imports from
viemto redirectwithCacheto stub - Applies to all files (not just
@wagmi/core) to handle porto dependencies
- Transforms imports from
-
resolve.aliasconfiguration:- Maps stub modules to actual stub files
- Maps
viem/utils/promise/withCacheto stub
The plugin uses enforce: 'pre' to ensure it runs before other plugins, allowing it to transform imports early in the build process.
client/src/lib/viem-actions-getCallsStatus-stub.ts- Re-exports from experimentalclient/src/lib/viem-actions-getCapabilities-stub.ts- Re-exports from experimentalclient/src/lib/viem-actions-sendCallsSync-stub.ts- Throws error stubclient/src/lib/viem-actions-sendTransactionSync-stub.ts- Throws error stubclient/src/lib/viem-actions-waitForCallsStatus-stub.ts- Throws error stubclient/src/lib/viem-actions-prepareAuthorization-stub.ts- Throws error stubclient/src/lib/viem-withCache-stub.ts- Simple implementation stub
-
vite.config.ts- Major changes:- Added
fsimport - Created
viemCompatibilityFixplugin with 3 hooks - Added 5 new alias mappings
- Plugin configured with
enforce: 'pre'
- Added
-
client/src/lib/viem-erc7821-stub.ts- Enhanced with:getExecuteErrorexportencodeExecuteDataexport
❌ Build failed immediately with:
"getCapabilities" is not exported by "viem/actions"
✅ Original error resolved
⚠️ Build progresses further but may encounter additional compatibility issues
-
✅ COMPLETED: Fix immediate build blockers
- All critical import errors resolved
- Build can now progress further
-
Monitor for additional issues:
- Watch for runtime errors from stub functions
- Some functions may need proper implementations instead of error-throwing stubs
-
Consider upgrading dependencies:
- Upgrade
wagmito latest version (if compatible) - Upgrade
viemto latest version (if compatible) - Check for version compatibility matrix
- Upgrade
-
Implement proper stubs:
- Replace error-throwing stubs with functional implementations where possible
- Especially for
withCachewhich has a simple implementation
-
Document workarounds:
- Document which features are unavailable due to version mismatches
- Add runtime checks/warnings when stub functions are called
-
Version alignment:
- Align
wagmiandviemversions to officially supported combinations - Consider using version ranges that are known to work together
- Align
-
Dependency audit:
- Review all wallet-related dependencies for compatibility
- Consider consolidating to fewer, well-maintained packages
-
Testing:
- Add integration tests for wallet functionality
- Test with different wallet providers
- Verify all EIP-5792 features work correctly
- Functions that re-export from
viem/experimental(getCapabilities, getCallsStatus, etc.) - These are just redirecting to the correct location
- Functions with simple stub implementations (withCache)
- May need proper implementation if caching is critical
- Functions that throw errors (sendCallsSync, sendTransactionSync, etc.)
- These will break at runtime if called
- Code using these functions needs to be updated or these functions need proper implementations
- Build completes successfully
- No import errors in browser console
- Wallet connection works
- Transaction sending works (if using sendTransaction, not sendTransactionSync)
- EIP-5792 features work (getCapabilities, sendCalls, etc.)
- No runtime errors from stub functions
- Test with multiple wallet providers
Current:
viem:2.21.4(pinned in overrides)wagmi:^2.19.5@wagmi/core: (transitive dependency)
Recommended:
- Check wagmi documentation for compatible viem versions
- Consider upgrading to latest compatible versions
-
Stub Functions: Several stub functions throw errors. If your code uses these functions, you'll need to either:
- Upgrade viem to a version that includes them
- Implement proper functionality in the stubs
- Refactor code to use alternative functions
-
Experimental Features: EIP-5792 functions are in
viem/experimental, indicating they're still experimental. Use with caution. -
Build Performance: The transform plugin adds minimal overhead but processes many files. Monitor build times.
-
Maintenance: This solution requires maintenance as wagmi/viem versions change. Consider this a temporary workaround until versions are aligned.
The original build error has been resolved. The solution uses a combination of:
- Import redirections (for functions in wrong locations)
- Stub implementations (for missing functions)
- Vite plugin transforms (to apply fixes automatically)
Status: ✅ Primary issue resolved. Additional compatibility work may be needed as the codebase evolves.
Report Generated: 2024-12-19
Audited By: AI Assistant
Next Review: When upgrading wagmi/viem dependencies