Skip to main content
Utilities to help configure your bundler (Vite, Webpack, or Next.js) to properly resolve the jose library dependency.

Overview

logto-authkit uses the jose library for JWT operations. Some bundlers require special configuration to properly resolve this dependency. These utilities provide the necessary configuration for different build tools.

Functions

getBundlerConfig

Returns bundler-specific configuration for resolving the jose library.
bundler
'vite' | 'webpack' | 'nextjs'
default:"vite"
The bundler type to generate configuration for
Returns: BundlerConfig - Configuration object specific to the bundler

Pre-configured Exports

viteConfig

Pre-configured settings for Vite projects.

webpackConfig

Pre-configured settings for Webpack projects.

nextjsConfig

Pre-configured settings for Next.js projects.

Type Definitions

BundlerConfig

optimizeDeps
{ include: string[] }
Vite-specific dependency optimization settings
resolve
{ alias: Record<string, string> }
Module resolution aliases
alias
Record<string, string>
Alternative alias format for some bundlers

Usage Examples

Vite

Add to your vite.config.ts:
Or use the function:

Webpack

Add to your webpack.config.js:

Next.js

Add to your next.config.js:
Or in TypeScript (next.config.ts):

Custom Bundler

For other bundlers, use the getBundlerConfig function:

What Does This Fix?

The jose library has different builds for different environments. These configurations ensure that:
  1. The correct CommonJS build is used (jose/dist/node/cjs)
  2. Dependencies are properly optimized for Vite
  3. Module resolution works correctly across different bundlers
Without this configuration, you may encounter errors like:
  • Cannot find module 'jose'
  • Error: Package subpath './jwt/verify' is not defined
  • Module resolution failures during build

Configuration Details

Vite Configuration

Webpack/Next.js Configuration