Skip to content

@workos-inc/node is being loaded in browser causing "pluralize module not found" error with Convex integration #18

@sc30gsw

Description

@sc30gsw

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:

  1. Create a new TanStack Start project with Convex integration
  2. Install @workos/authkit-tanstack-react-start@0.2.0
  3. Configure WorkOS AuthKit following the official documentation
  4. Add AuthKitProvider with ConvexProviderWithAuth

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:

  1. Run npm run dev
  2. Navigate to http://localhost:3000
  3. Check browser console - pluralize error blocks all JavaScript

Expected behavior

  • @workos-inc/node should never be loaded in the browser
  • The library should properly separate client-side and server-side code
  • AuthKitProvider and useAuth() should work correctly with Convex integration

Actual behavior

  • @workos-inc/node is loaded in the browser
  • pluralize module 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

  1. Official example works fine (without Convex integration)
  2. Server-side authentication works - getAuth() in loaders successfully returns user data
  3. Only client-side fails - useAuth() hook causes the browser error
  4. No Vite SSR configuration helps - Tried various ssr.external, optimizeDeps.exclude settings with no success

Attempted Solutions

  1. ✗ Added @workos-inc/node to ssr.external in vite.config.ts
  2. ✗ Added pluralize to optimizeDeps.exclude
  3. ✗ Tried aliasing pluralize to empty module
  4. ✗ 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions