-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
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:
- micromatch v4.x doesn't export a
bracesfunction directly - braces is a separate package (
braces) that micromatch uses internally - ContentLayer2 is incorrectly trying to access
micromatch.braces()instead of importingbracesdirectly
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 correctlyMetadata
Metadata
Assignees
Labels
No labels