bug: Cannot read properties of undefined (reading 'keyPrefix')
Problem
Provide environment information [code block] Describe the bug After upgrading to trpc 11.7.0 from trpc 11.6.0, our Next.js app crashes on the client-side with errror: [code block] Link to reproduction N/A To reproduce Upgrading to trpc 11.7.0 Additional information _No response_ ๐จโ๐งโ๐ฆ Contributing - [ ] ๐โโ๏ธ Yes, I'd be down to file a PR fixing this bug!
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix undefined 'keyPrefix' error after upgrading to trpc 11.7.0
The error occurs because the upgrade to trpc 11.7.0 introduced changes in how the client configuration is handled. Specifically, the 'keyPrefix' property is expected to be defined in the configuration object but is missing or incorrectly set, leading to attempts to read properties of undefined.
Awaiting Verification
Be the first to verify this fix
- 1
Check trpc client configuration
Review the trpc client configuration in your Next.js app to ensure that the 'keyPrefix' property is defined. This property is crucial for managing cache keys and should be set according to your application's requirements.
typescriptconst trpcClient = createTRPCClient({ url: '/api/trpc', keyPrefix: 'myAppPrefix', // Ensure this is defined }); - 2
Update dependencies
Ensure that all related dependencies are updated to their latest compatible versions. This includes checking for any peer dependencies that may also need to be updated alongside trpc.
bashnpm install trpc@latest - 3
Review breaking changes
Consult the trpc release notes for version 11.7.0 to identify any breaking changes that may affect your application. Adjust your code accordingly to accommodate these changes.
markdownhttps://github.com/trpc/trpc/releases/tag/v11.7.0 - 4
Test the application
Run your Next.js application locally and test the client-side functionality to ensure that the error no longer occurs. Pay special attention to areas where the trpc client is used.
bashnpm run dev
Validation
Confirm that the application runs without crashing and that the 'keyPrefix' error no longer appears in the console. Additionally, verify that all trpc-related functionality operates as expected.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep