fix(nextjs): Improve auth() misimport from main entry point#8487
fix(nextjs): Improve auth() misimport from main entry point#8487alexcarpenter wants to merge 3 commits intomainfrom
Conversation
…oint When developers import `auth` from `@clerk/nextjs` instead of `@clerk/nextjs/server`, the bundler shows a generic "'auth' is not exported" error with no guidance. Replace the type-only `declare const` stub with a real runtime Proxy export that throws a clear error message pointing to the correct import path. Ref: SDK-65 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 140d334 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThis PR adds a deprecation notice to the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
|
!snapshot |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
| * API Routes, Server Components, Server Actions, and Middleware. | ||
| */ | ||
| export declare const auth: never; | ||
| export { auth } from './server-only-stubs'; |
There was a problem hiding this comment.
Does this approach move the error from being a build time one to being a runtime one? I'm not sure we should do that, I'd rather take a less specific error at build time than a great one at runtime or else users risk deploying bugs to production before catching the error?
I didn't think much about feasibility or where the current message was coming from when I wrote the issue. :/
There was a problem hiding this comment.
yeah, I agree the tradeoff probably isn't worth it. losing the build-time check to improve a runtime error risks letting misimports ship to production for that subset of users.
wdyt about adding a @deprecated jsdoc notice? 140d334
There was a problem hiding this comment.
That's clever and likely the best we can do, I like it!
Ephem
left a comment
There was a problem hiding this comment.
I like it! 🙏
NIT: Maybe update(/remove) the PR description before merging to avoid someone being confused in the future.
|
FYI: I considered using the |
Summary
Improved developer experience when
authis accidentally imported from@clerk/nextjsinstead of@clerk/nextjs/server. Theauthexport now includes a@deprecatedJSDoc tag with a clear message guiding developers to the correct import path, visible on hover in IDEs.Ref: SDK-65
Test plan
auth-misimport.test.tscovering both function call and property access scenariosimport { auth } from '@clerk/nextjs'shows the new error instead of the bundler error🤖 Generated with Claude Code