Skip to content

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Sep 19, 2025

Description

This PR is just a testing ground for a potential ESM-only version of @clerk/clerk-react.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Chores

    • Added release metadata for a minor update.
    • Switched the React package to ESM-only output.
    • Simplified package exports to use default and types mappings.
    • Updated TypeScript config to align with bundler-based module resolution.
    • Adjusted build configuration to emit only ESM bundles.
  • Impact

    • Consumers should use ESM imports; CommonJS require is no longer supported.
    • No runtime or API changes; behavior remains the same.

Copy link

changeset-bot bot commented Sep 19, 2025

🦋 Changeset detected

Latest commit: 84c3897

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@clerk/clerk-react Minor
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/clerk-expo Patch
@clerk/nextjs Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch

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

Copy link

vercel bot commented Sep 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Sep 19, 2025 9:56pm

Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Shifts the React package to ESM-only: sets "type": "module", simplifies exports to "types"/"default", updates tsup to emit only ESM, and adjusts TypeScript module/moduleResolution. Adds a changeset marking a minor release for @clerk/clerk-react. No source code or runtime logic changes.

Changes

Cohort / File(s) Change summary
Release metadata
.changeset/red-horses-type.md
Added changeset declaring a minor release for @clerk/clerk-react; contains YAML-like block and a "wip" line.
React package ESM migration
packages/react/package.json, packages/react/tsconfig.json, packages/react/tsup.config.ts
package.json: set "type":"module", replaced per-env import/require exports with "types"/"default" mappings for ., ./internal, ./errors, ./experimental. tsconfig.json: moduleResolutionbundler, modulepreserve. tsup.config.ts: format from ['cjs','esm'] to 'esm' (ESM-only build).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paw: to ESM we hop,
Bundles light as clover on the top.
Exports tidy, types aligned—how neat!
Tsup sings ESM, a single beat.
Changeset whispers, “minor leap,”
I twitch my nose—and bounds I keep. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat(clerk-react): Test ESM-only clerk-react" concisely and accurately summarizes the primary change under review — moving clerk-react toward an ESM-only configuration (package.json type: module, tsup changed to emit ESM only, tsconfig/exports adjustments). It is specific, focused, and understandable for teammates scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ds.feat/react-esm

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

pkg-pr-new bot commented Sep 19, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6821

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6821

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6821

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6821

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6821

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6821

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6821

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6821

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6821

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6821

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6821

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6821

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6821

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6821

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6821

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6821

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6821

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6821

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6821

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6821

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6821

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6821

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6821

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6821

commit: 84c3897

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.changeset/red-horses-type.md (1)

1-6: Complete the changeset description.

The changeset correctly marks this as a minor release but needs a proper description explaining the breaking change nature of moving to ESM-only.

Apply this diff to provide a complete changeset description:

 ---
 '@clerk/clerk-react': minor
 ---
 
-wip
+Convert @clerk/clerk-react to ESM-only package. This removes CommonJS support and requires Node.js environments that support ES modules.
🧹 Nitpick comments (1)
packages/react/package.json (1)

45-45: Consider removing the main field for ESM-only packages.

The main field is primarily for CommonJS compatibility. Since this is now an ESM-only package, the main field might be redundant as modern tools should use the exports field.

Consider applying this diff to remove the redundant main field:

-  "main": "./dist/index.js",
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 651b27e and 84c3897.

📒 Files selected for processing (4)
  • .changeset/red-horses-type.md (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/tsconfig.json (1 hunks)
  • packages/react/tsup.config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/red-horses-type.md
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/react/tsup.config.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/react/tsup.config.ts
  • packages/react/tsconfig.json
  • packages/react/package.json
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/react/tsup.config.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/react/tsup.config.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/react/tsup.config.ts
packages/*/tsup.config.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

TypeScript compilation and bundling must use tsup.

Files:

  • packages/react/tsup.config.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/react/tsup.config.ts
packages/*/tsconfig.json

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Type checking must be performed with TypeScript and publint.

Files:

  • packages/react/tsconfig.json
packages/*/package.json

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/react/package.json
⏰ 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). (4)
  • GitHub Check: Build Packages
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
packages/react/tsconfig.json (1)

9-10: LGTM! TypeScript configuration aligns with ESM-only build.

The changes to moduleResolution: "bundler" and module: "preserve" are appropriate for the ESM-only transformation. These settings work well with modern bundlers and preserve the original module format during TypeScript compilation, letting tsup handle the final ESM output.

packages/react/package.json (3)

25-25: LGTM! Enables ES module support.

Adding "type": "module" correctly marks this package as an ES module, which is essential for the ESM-only transformation.


26-44: Export paths verified — no action required.

tsup (packages/react/tsup.config.ts) defines entries index/internal/errors/experimental with dts: true and the matching source files exist (packages/react/src/{index,internal,errors,experimental}.ts), so the package.json exports align with the build outputs.


82-84: Confirm Node.js 18.17.0 supports the ESM features used

File: packages/react/package.json
Lines: 82-84

  "engines": {
    "node": ">=18.17.0"
  },

18.17.0 is LTS and supports standard ESM (import/export, dynamic import, top-level await). Verify the repo does not rely on experimental ESM features (JSON import assertions, import.meta.resolve, WASM imports) or synchronous CJS→ESM require; if it does, raise the engines range or add compatibility shims.

packages/react/tsup.config.ts (1)

19-19: Verify impact of removing CommonJS support across the ecosystem — repo scan results

  • Scan of the repo (script output) found NO in-repo CommonJS usage of @clerk/clerk-react (no require('@clerk/clerk-react') or module.exports referencing that package).
  • Repo occurrences: ES import in playground/cra-js/src/App.js (import { ClerkProvider, SignIn } from '@clerk/clerk-react'); packages/upgrade/src/guide-generators/core-2/react/index.js contains the package name string; several jest.config.* files use module.exports (config files only).
  • Recommendation: still a breaking change for external CommonJS consumers — either restore CJS output or publish as ESM-only with a major-version bump, ensure package.json 'exports'/'main' and 'type' are correct, and add migration notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants