Skip to content

fix(nuxt): read correct env vars at build time for tests#7382

Closed
wobsoriano wants to merge 3 commits intomainfrom
rob/fix-nuxt-e2e
Closed

fix(nuxt): read correct env vars at build time for tests#7382
wobsoriano wants to merge 3 commits intomainfrom
rob/fix-nuxt-e2e

Conversation

@wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Dec 5, 2025

Description

  • Adds process.env fallbacks for clerkJSUrl, clerkJSVariant, and clerkJSVersion options in the Nuxt module
  • Fixes E2E tests not using the local clerk js url due to env var naming mismatch

Problem

Nuxt's runtime config nests options under clerk, so the env var for clerkJSUrl needs to be NUXT_PUBLIC_CLERK_CLERK_JS_URL (double CLERK). However, the E2E test framework sets NUXT_PUBLIC_CLERK_JS_URL, which wasn't being read.

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

  • New Features
    • Build-time environment variable support for Clerk JS configuration (URL, variant, version) when corresponding options are not explicitly provided.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

🦋 Changeset detected

Latest commit: 7187e75

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

This PR includes changesets to release 1 package
Name Type
@clerk/nuxt 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

@vercel
Copy link

vercel bot commented Dec 5, 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 Dec 5, 2025 9:22pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Walkthrough

Adds environment variable fallback support for Clerk JS configuration in the Nuxt module. When clerkJSUrl, clerkJSVariant, or clerkJSVersion options are not provided, the module now reads corresponding NUXT_PUBLIC_CLERK_JS_* environment variables at build time. A changeset documents the patch release.

Changes

Cohort / File(s) Summary
Changeset documentation
\.changeset/smooth-files-join.md
Documents a patch release for @clerk/nuxt with build-time support for NUXT_PUBLIC_CLERK_JS_* environment variables.
Clerk JS configuration fallbacks
packages/nuxt/src/module.ts
Replaces direct option usage with environment variable fallbacks for clerkJSUrl, clerkJSVariant, and clerkJSVersion. When options are not provided, the module reads from NUXT_PUBLIC_CLERK_JS_URL, NUXT_PUBLIC_CLERK_JS_VARIANT, and NUXT_PUBLIC_CLERK_JS_VERSION respectively at build/dev time.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward fallback logic with no complex control flow changes
  • Repetitive pattern applied consistently across three environment variables
  • Primarily configuration enhancements requiring basic verification of fallback correctness

Poem

🐰 Environment whispers at build time so dear,
JS config flows smoother, now loud and clear,
No options? No trouble—the vars take their place,
Clerk hops forth with grace! 🌟

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 title accurately describes the main change: adding build-time environment variable support for Nuxt module options (clerkJSUrl, clerkJSVariant, clerkJSVersion). The title is concise and specific about what was fixed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rob/fix-nuxt-e2e

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

Comment on lines +67 to +74
// Unfortunately, Nuxt's runtime config nests these under `clerk`, so the env var
// for `clerkJSUrl` would need to be NUXT_PUBLIC_CLERK_CLERK_JS_URL (double CLERK).
// To avoid this awkward naming, we read NUXT_PUBLIC_CLERK_JS_* directly via process.env
// at build/dev time, which is consistent with other Clerk packages.
// For both build and runtime overrides in production, use NUXT_PUBLIC_CLERK_CLERK_JS_* instead.
clerkJSUrl: options.clerkJSUrl || process.env.NUXT_PUBLIC_CLERK_JS_URL,
clerkJSVariant: options.clerkJSVariant || process.env.NUXT_PUBLIC_CLERK_JS_VARIANT,
clerkJSVersion: options.clerkJSVersion || process.env.NUXT_PUBLIC_CLERK_JS_VERSION,
Copy link
Member Author

Choose a reason for hiding this comment

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 5, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 7187e75

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

🧹 Nitpick comments (2)
packages/nuxt/src/module.ts (2)

67-74: Env var fallback looks correct; consider small clarity tweaks

The fallback logic (options.* || process.env.NUXT_PUBLIC_CLERK_JS_*) aligns with the goal of honoring NUXT_PUBLIC_CLERK_JS_* at build/dev time while still allowing Nuxt’s runtime config to handle the NUXT_PUBLIC_CLERK_CLERK_JS_* pattern.

Two optional nits you may want to consider:

  • If an explicitly empty string should ever be a valid override, ?? would be slightly safer than || to avoid treating '' as “unset”:
    clerkJSUrl: options.clerkJSUrl ?? process.env.NUXT_PUBLIC_CLERK_JS_URL,
  • The comment about “For both build and runtime overrides in production, use NUXT_PUBLIC_CLERK_CLERK_JS_* instead” could be misread, since this block only reads the non‑nested NUXT_PUBLIC_CLERK_JS_* via process.env. You might want to explicitly state which naming pattern affects build‑time defaults (single‑CLERK) vs Nuxt runtime overrides (double‑CLERK) so users know when they may need to set both.

1-1: Prefer @clerk/shared/types over @clerk/types for new work

Per the current guidelines, @clerk/types is a deprecated alias. When convenient, consider updating this import to pull Without from @clerk/shared/types instead:

-import type { Without } from '@clerk/types';
+import type { Without } from '@clerk/shared/types';

This is a non‑blocking, nice‑to‑have cleanup and can also be done in a follow‑up sweep.

📜 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 1bb6a46 and 7187e75.

📒 Files selected for processing (2)
  • .changeset/smooth-files-join.md (1 hunks)
  • packages/nuxt/src/module.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}

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

All code must pass ESLint checks with the project's configuration

Files:

  • packages/nuxt/src/module.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

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

Use Prettier for consistent code formatting

Files:

  • packages/nuxt/src/module.ts
packages/**/src/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/nuxt/src/module.ts
**/*.{ts,tsx,js,jsx}

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

Follow established naming conventions (PascalCase for components, camelCase for variables)

Prefer importing types from @clerk/shared/types instead of the deprecated @clerk/types alias

Files:

  • packages/nuxt/src/module.ts
packages/**/src/**/*.{ts,tsx,js,jsx}

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

packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
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
Implement proper logging with different levels

Files:

  • packages/nuxt/src/module.ts
**/*.ts?(x)

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

Use proper TypeScript error types

Files:

  • packages/nuxt/src/module.ts
**/*.{ts,tsx}

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

**/*.{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
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
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 in classes
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like <T extends { id: string }>
Use utility types like Omit, Partial, and Pick for data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Use const assertions with as const for literal types
Use satisfies operator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...

Files:

  • packages/nuxt/src/module.ts
⏰ 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). (9)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Unit Tests (22, shared, clerk-js, RQ)
  • GitHub Check: Static analysis
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/smooth-files-join.md (1)

1-5: Changeset accurately documents the behavioural change

Scope, bump type, and description match the new build‑time support for NUXT_PUBLIC_CLERK_JS_* in the Nuxt module. No changes needed here.

@wobsoriano wobsoriano closed this Dec 5, 2025
@wobsoriano
Copy link
Member Author

wobsoriano commented Dec 5, 2025

closed in favor of eefdea2

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.

3 participants