contentlayerdev / contentlayer

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://www.contentlayer.dev
MIT License
3.33k stars 200 forks source link

Could not find `contentlayer.config.ts` or `contentlayer.config.js` in source #670

Open SanyamPunia opened 2 months ago

SanyamPunia commented 2 months ago

I'm trying to configure my blogs/docs using contentlayer in a Next.js project.

"next": "14.2.5",
"contentlayer": "^0.3.4",
"next-contentlayer": "^0.3.4",

When I run yarn contentlayer build or yarn contentlayer dev, I receive the following error:

Warning: Contentlayer might not work as expected on Windows
Could not find contentlayer.config.ts or contentlayer.config.js in `your source`

The contentlayer.config.js file is located at the root of my project, and my configuration looks like this:

import { defineDocumentType, makeSource } from "contentlayer/source-files";

/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
  slug: {
    type: "string",
    resolve: (doc) => `/${doc._raw.flattenedPath}`,
  },
  slugAsParams: {
    type: "string",
    resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
  },
};

export const Doc = defineDocumentType(() => ({
  name: "Doc",
  filePathPattern: `docs/**/*.mdx`,
  contentType: "mdx",
  fields: {
    title: {
      type: "string",
      required: true,
    },
    description: {
      type: "string",
    },
    published: {
      type: "boolean",
      default: true,
    },
  },
  computedFields,
}));

export default makeSource({
  contentDirPath: "./content",
  documentTypes: [Doc]
});

Here’s my directory structure:

project
├── app
├── package.json
├── contentlayer.config.js
├── tsconfig.json
└── ...rest

Is contentlayer not compatible with the latest Next.js version, or is there something wrong with my configuration? Any help would be appreciated!

TontofourK commented 1 month ago

facing a similar issue, did you found any solution to it?