-
Notifications
You must be signed in to change notification settings - Fork 419
fix: replace cookie with cookie-es to fix Vite ESM compatibility #7525
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
Conversation
Fixes clerk#7522 Fixes clerk#7453 The cookie package's named exports don't work properly in Vite's dev mode with ESM, causing the error: "The requested module (cookie) does not provide an export named 'parse'" This issue occurs specifically in Vite environments (like TanStack Start) where the cookie package is not properly transformed for ESM consumption, leading to runtime errors during development. Changes: - Replace "cookie": "1.0.2" with "cookie-es": "^1.3.1" in backend package.json - Update import statement in clerkRequest.ts from 'cookie' to 'cookie-es' cookie-es is a modern ESM-first package that provides the same API as cookie but with proper ES module support, eliminating the need for Vite workarounds like adding cookie to optimizeDeps. This fix resolves the issue at its root rather than requiring users to configure their bundler settings.
|
|
@Ayush2k02 is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis change replaces the Pre-merge checks✅ Passed checks (5 passed)
📜 Recent review detailsConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (12)**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.ts?(x)📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*⚙️ CodeRabbit configuration file
Files:
packages/*/package.json📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/package.json📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (2)
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 |
|
Hello! Thank you for this but we're closing this PR in favor of #7524. The PR bundles the |
|
Yeah, makes a lot of sense to go #7524 |
Summary
Fixes #7522
Fixes #7453
This PR replaces the
cookiepackage withcookie-esin@clerk/backendto fix ESM compatibility issues in Vite environments.Problem
When using
@clerk/tanstack-react-start(or any Clerk package that depends on@clerk/backend) in Vite dev mode, users encounter this error:This happens because:
cookiepackage uses CommonJS-style exports that don't work well with Vite's ESM transformationsimport { parse } from 'cookie') but the package doesn't properly expose them in ESM environmentsCurrent Workarounds
Users had to add Vite config workarounds:
Or use dynamic imports to avoid pulling server modules into client bundles.
Solution
Replace
cookiewithcookie-es:cookie-esis a modern, ESM-first packagecookieChanges Made
"cookie": "1.0.2"with"cookie-es": "^1.3.1"'cookie'to'cookie-es'Benefits
✅ No more Vite configuration required - Users don't need to add
optimizeDepsconfig✅ Same API -
cookie-esis a drop-in replacement with identical function signatures✅ Modern ESM support - Proper ES module exports work correctly in all environments
✅ Fixes the root cause - Rather than working around the bundler, we use a package designed for ESM
Testing
The
parsefunction fromcookie-eshas the same signature and behavior as the one fromcookie:Existing tests should continue to pass without modification.
Impact
This change affects the
@clerk/backendpackage, which is consumed by:@clerk/tanstack-react-start@clerk/nextjs@clerk/remixAll of these will benefit from improved ESM compatibility.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.