Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SanyamPunia opened this issue Sep 14, 2024 · 1 comment

Comments

@SanyamPunia
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants