Here is my next.config.js:
const { withContentlayer } = require("next-contentlayer");
module.exports = withContentlayer({
experimental: { appDir: true },
});
Here is my tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"baseUrl": ".",
"paths": {
"contentlayer/generated": ["./.contentlayer/generated"],
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".contentlayer/generated"
],
"exclude": ["node_modules"]
}
Here is my contentlayer.config.ts:
import { defineDocumentType, makeSource } from "contentlayer/source-files";
const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the post",
required: true,
},
date: {
type: "date",
description: "The date of the post",
required: true,
},
},
computedFields: {
url: {
type: "string",
resolve: (doc) => `/posts/${doc._raw.flattenedPath}`,
},
},
}));
export default makeSource({
contentDirPath: "posts",
documentTypes: [Post],
});
Here is my package.json:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@types/node": "18.15.11",
"@types/react": "18.0.34",
"@types/react-dom": "18.0.11",
"autoprefixer": "10.4.14",
"contentlayer": "^0.3.1",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"next": "13.3.0",
"next-contentlayer": "^0.3.1",
"postcss": "8.4.21",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.1",
"typescript": "5.0.4"
}
}
I also have a folder named posts with an example.mdx file:
---
title: Change me!
date: 2022-03-11
---
When you change a source file, Contentlayer automatically updates the content cache, which prompts Next.js to reload the content on screen.
Can you please tell me what I'm doing wrong?
I want to get my next js 13 app to generate the .contentlayer/generated folder, but when I run the program, while it doesnt give me any errors or warnings, it doesn't generate the folder either.
As stated from this comment on this github issue
The workaround is to run
contentlayer devalso like soI have tested this to be working on the following versions