posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

PostHog CLI glob parser fails on Next.js catch-all routes [[...slug]]

Open paulodearaujo opened this issue 1 month ago • 2 comments

Bug description

When using @posthog/nextjs-config with sourcemap uploads enabled, the PostHog CLI fails to parse Next.js catch-all route patterns like [[...sign-in]] or [[...slug]].

The CLI's glob parser incorrectly interprets the [...] syntax inside the route name as a character range pattern. For example, [[...sign-in]] is parsed as containing [n-i], which fails because 'n' > 'i' in ASCII order.

Error message:

ERROR posthog_cli::commands: msg="Oops! error parsing glob '**/app/(auth)/sign-in/[[...sign-in]]/page.js': invalid range; 'n' > 'i'"
Oops! error parsing glob '**/app/(auth)/sign-in/[[...sign-in]]/page.js': invalid range; 'n' > 'i'
[PostHog Webpack] Error running PostHog sourcemap plugin: Command failed with code 1

Expected behavior: The CLI should escape or handle Next.js routing conventions ([[...slug]], [...slug], [slug]) which are valid filesystem paths, not glob character ranges.

Actual behavior: The CLI treats square brackets in filenames as glob syntax, causing parsing failures.

How to reproduce

  1. Create a Next.js 15 App Router project with Clerk authentication (or any catch-all route)
  2. Add a catch-all route like app/(auth)/sign-in/[[...sign-in]]/page.tsx
  3. Configure @posthog/nextjs-config with sourcemaps enabled:
    import { withPostHogConfig } from "@posthog/nextjs-config";
    
    export default withPostHogConfig(nextConfig, {
      personalApiKey: process.env.POSTHOG_API_KEY,
      envId: process.env.POSTHOG_ENV_ID,
      sourcemaps: { enabled: true, deleteAfterUpload: true },
    });
    
  4. Run next build
  5. Observe the glob parsing error

Impact

  • The build completes successfully despite the error
  • Sourcemaps for routes with catch-all patterns are not uploaded
  • Other sourcemaps upload correctly

Environment

  • Next.js: 15.5.7
  • @posthog/nextjs-config: 1.6.4
  • OS: macOS 15.6 (also reproducible on Linux)
  • Node: 22.x
  • Package manager: pnpm

Suggested fix

The glob library used by posthog-cli should escape square brackets in file paths before constructing glob patterns, or use a literal path matching approach for sourcemap file discovery instead of glob patterns.

Alternatively, paths containing [[ or [... should be treated as literal strings rather than glob syntax.

Related sub-libraries

  • [x] @posthog/nextjs-config
  • [x] posthog-cli (Rust CLI)

Workaround

Set POSTHOG_SOURCEMAPS=false in environment to disable sourcemap uploads entirely, or accept that catch-all route sourcemaps won't be uploaded.

paulodearaujo avatar Dec 11 '25 20:12 paulodearaujo

@PostHog/team-error-tracking

marandaneto avatar Dec 16 '25 09:12 marandaneto

@paulodearaujo Could you try with the latest nextjs-config version (1.7.1) ? It should have been fixed

hpouillot avatar Dec 16 '25 10:12 hpouillot