Skip to content

ContentLayer2 v0.5.8 causes a critical production build failure due to incompatibility with micromatch dependency #89

Description

@issam-seghir

The error occurs when contentlayer2 attempts to call micromatch.braces() which doesn't exist in the current micromatch API.

Details

Error Message:

TypeError: micromatch.braces is not a function
    at Object.<anonymous> (node_modules/contentlayer2/dist/core/index.js:xxx:xx)
    at Module._compile (node_modules/contentlayer2/dist/core/index.js)
    at Object.Module._extensions..js (module.js:xxx:xx)

Stack Trace:

Error occurred during Next.js production build
TypeError: micromatch.braces is not a function
    at contentlayer2/dist/core/index.js
    at webpack compilation
    at production build process

Environment

  • ContentLayer2 Version: 0.5.8
  • Next.js Version: 15.4.5
  • Node.js Version: 22.17.0
  • Package Manager: pnpm
  • Environment: Production build (works in development)
  • Platform: Coolify VPS Deployment**

Dependencies

{
  "contentlayer2": "^0.5.8",
   "next-contentlayer2": "^0.5.8",
  "next": "15.4.5",
}

Steps to Reproduce

Minimal Reproduction:

contentlayer.config.ts:

import { defineDocumentType, makeSource } from 'contentlayer2/source-files'

export const Post = defineDocumentType(() => ({
  name: 'Post',
  filePathPattern: `**/*.mdx`,
  contentType: 'mdx',
  fields: {
    title: { type: 'string', required: true },
  },
}))

export default makeSource({
  contentDirPath: './content',
  documentTypes: [Post],
})

next.config.mjs:

import { withContentlayer } from 'nextjs-contentlayer2'

/** @type {import('next').NextConfig} */
const nextConfig = {
  // basic config
}

export default withContentlayer(nextConfig)

Expected Behavior

ContentLayer2 should successfully compile during production builds without micromatch-related errors.

Actual Behavior

Production build fails with TypeError: micromatch.braces is not a function, preventing deployment.

Root Cause Analysis

The issue appears to be in contentlayer2's usage of the micromatch library. Based on investigation:

  1. micromatch v4.x doesn't export a braces function directly
  2. braces is a separate package (braces) that micromatch uses internally
  3. ContentLayer2 is incorrectly trying to access micromatch.braces() instead of importing braces directly

Micromatch API (v4.x):

// ❌ INCORRECT (what contentlayer2 is doing)
import micromatch from 'micromatch'
micromatch.braces() // TypeError: not a function

// ✅ CORRECT (what should be done)
import braces from 'braces'
braces() // Works correctly

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions