-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Describe the bug
When using @workos/authkit-tanstack-react-start with Convex integration, the Node.js-only dependency @workos-inc/node is being loaded in the browser, causing a module resolution error for pluralize.
The error completely blocks JavaScript execution, preventing the application from functioning.
Error Messages
GET http://localhost:3000/node_modules/@workos-inc/node/lib/esm/common/exceptions/unprocessable-entity.exception.js
net::ERR_ABORTED 500 (Internal Server Error)
Uncaught (in promise) SyntaxError: The requested module '/node_modules/pluralize/pluralize.js' does not provide an export named 'default'
(at unprocessable-entity.exception.js:3:8)
Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: http://localhost:3000/@id/virtual:tanstack-start-client-entry
The problematic code from @workos-inc/node:
import pluralize from "/node_modules/pluralize/pluralize.js";
class UnprocessableEntityException extends Error {
// ... rest of the code
}To Reproduce
Setup:
- Create a new TanStack Start project with Convex integration
- Install
@workos/authkit-tanstack-react-start@0.2.0 - Configure WorkOS AuthKit following the official documentation
- Add
AuthKitProviderwithConvexProviderWithAuth
File structure:
src/router.tsx:
import { AuthKitProvider } from '@workos/authkit-tanstack-react-start/client';
import { ConvexProviderWithAuth } from 'convex/react';
export function getRouter() {
const router = createRouter({
routeTree,
context: { queryClient, convexClient: convex, convexQueryClient },
Wrap: ({ children }) => (
<AuthKitProvider>
<ConvexProviderWithAuth client={convexQueryClient.convexClient} useAuth={useAuthFromWorkOS}>
{children}
</ConvexProviderWithAuth>
</AuthKitProvider>
),
});
return router;
}vite.config.ts:
import { defineConfig } from 'vite';
import tsConfigPaths from 'vite-tsconfig-paths';
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import viteReact from '@vitejs/plugin-react';
export default defineConfig({
server: { port: 3000 },
plugins: [tsConfigPaths(), tanstackStart(), viteReact()],
});Steps:
- Run
npm run dev - Navigate to
http://localhost:3000 - Check browser console -
pluralizeerror blocks all JavaScript
Expected behavior
@workos-inc/nodeshould never be loaded in the browser- The library should properly separate client-side and server-side code
AuthKitProvideranduseAuth()should work correctly with Convex integration
Actual behavior
@workos-inc/nodeis loaded in the browserpluralizemodule error blocks JavaScript execution- Application completely non-functional
Environment
{
"@workos/authkit-tanstack-react-start": "0.2.0",
"@tanstack/react-router": "^1.132.41",
"@tanstack/react-start": "^1.132.43",
"convex": "^1.28.0",
"@convex-dev/react-query": "^0.0.0-alpha.11",
"vite": "^7.1.8"
}Dependency tree:
@workos/authkit-tanstack-react-start@0.2.0
└─┬ @workos/authkit-session@0.1.2
└── @workos-inc/node@8.0.0-rc.2
└── pluralize@8.0.0
Node.js: v20.x
Browser: Chrome/Safari (latest)
OS: macOS
Observations
- Official example works fine (without Convex integration)
- Server-side authentication works -
getAuth()in loaders successfully returns user data - Only client-side fails -
useAuth()hook causes the browser error - No Vite SSR configuration helps - Tried various
ssr.external,optimizeDeps.excludesettings with no success
Attempted Solutions
- ✗ Added
@workos-inc/nodetossr.externalin vite.config.ts - ✗ Added
pluralizetooptimizeDeps.exclude - ✗ Tried aliasing
pluralizeto empty module - ✗ Cleared all caches and reinstalled dependencies
None of these resolved the issue.
Possible Root Cause
The @workos/authkit-tanstack-react-start/client export may not be properly isolating client-side code from server-side dependencies. The @workos-inc/node package should only be imported on the server, but appears to be bundled for the client.
Workaround Needed
Is there a recommended way to use WorkOS AuthKit with Convex in TanStack Start that avoids this issue?