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 201 forks source link

No `.contentlayer` folder is generated in Next.js 13.3 #415

Closed qiushiyan closed 1 year ago

qiushiyan commented 1 year ago

Seems contentlayer is currently imcompatible with the latest version of Next.js 13.3, when I run next dev non .contentlayer folder is generated.

I cloned the package.json, next.config.js and contentlayer config file from the example project and run the following comand to update nextjs

pnpm add next@latest react@latest react-dom@latest

After this pnpm run dev does not generated the .contentlayer folder.

example repo

cibulka commented 1 year ago

Yes, having the same problem. Downgrading to 13.2.4 works, assuming you overwrote telemetry dependency as described here.

kamtorocks commented 1 year ago

Same problem, but downgrading to 13.2.4 will encounter other next problems, can anyone provide some help?

kamtorocks commented 1 year ago

I have found the cause of this problem. Since next@v13.2.5-canary.27, next dev has been using jest-worker to start the service.

Using a version below next@v13.2.5-canary.26 will not have this problem. Of course, the best solution is to optimize the way of next config plugin.

nkilm commented 1 year ago

what triggers the creation of .contentlayer folder? I have degraded my nextjs version to 13.2.4 from 13.3.0 but the folder is still not getting generated.

// next.config.js

/** @type {import('next').NextConfig} */
const { withContentlayer } = require("next-contentlayer");

const nextConfig = {
  reactStrictMode: true,
  distDir: "build",
  experimental: {
    appDir: true,
  },
};

module.exports = withContentlayer(nextConfig);
haaarshsingh commented 1 year ago

Just saw this issue. My contentlayer is working fine (check: harshhhdev/www), but it's because I'm using 0.3.0 instead of 0.3.1.

sean-clayton commented 1 year ago

Is this a bug with Next 13.3 or is it a bug with contentlayer?

kamtorocks commented 1 year ago

Is this a bug with Next 13.3 or is it a bug with contentlayer?

It's just a matter of how the plugin is started

thara003 commented 1 year ago

I too have the same issue, here's my package.json

    "next": "13.3.0",
    "next-contentlayer": "^0.3.0",
    "contentlayer": "^0.3.0",

also tried downgrading the versions just like the contentlayer-example still the issue persist.

millievn commented 1 year ago

work fine with these configs( see my forked example ):

 "next": "13.2.4",
 "next-contentlayer": "0.3.1",
"contentlayer": "0.3.1"
skwowet commented 1 year ago

@qiwang97 these are same versions used in contentlayer-example, but still it doesn't work.

    "contentlayer": "^0.3.0",
    "next": "13.2.5-canary.16",
    "next-contentlayer": "^0.3.0",

I used the above example from leerob's portfolio repository and it works fine.

TheBinaryGuy commented 1 year ago

Until this is resolved, you can either use concurrently to work around this:

{
  // ---
  "scripts": {
    "dev": "concurrently \"contentlayer dev\" \"next dev\"",
    "build": "contentlayer build && next build"
  }
  / ---
}

Or have 2 different scripts for development and run them both in different tabs:

{
  // ---
  "scripts": {
    "cl-dev": "contentlayer dev",
    "dev": "next dev",
    "build": "contentlayer build && next build"
  }
  / ---
}
gsen commented 1 year ago

Local fix until this issue is resolved. You can update the dev script in package.json and make use of the content layer cli as follows:

"scripts": {
    "dev": "contentlayer dev & next dev"
}

then run pnpm dev

Content layer cli - https://www.contentlayer.dev/docs/reference/cli#dev

nkilm commented 1 year ago

@qiwang97 these are same versions used in contentlayer-example, but still it doesn't work.

    "contentlayer": "^0.3.0",
    "next": "13.2.5-canary.16",
    "next-contentlayer": "^0.3.0",

I used the above example from leerob's portfolio repository and it works fine.

Thank you! This versions are working for meπŸŽ‰

Alterly, you can try npx contentlayer dev, it also generates the .contentlayer folder.

eric-hendrickson commented 1 year ago

@qiwang97 these are same versions used in contentlayer-example, but still it doesn't work.

    "contentlayer": "^0.3.0",
    "next": "13.2.5-canary.16",
    "next-contentlayer": "^0.3.0",

I used the above example from leerob's portfolio repository and it works fine.

Thank you! This versions are working for meπŸŽ‰

Alterly, you can try npx contentlayer dev, it also generates the .contentlayer folder.

In order to generate the .contentlayer/generated folder, you will need to run npx contentlayer postinstall as well. I don't know why that isn't being run when I run npx contentlayer dev or npx contentlayer build though. :shrug:

EDIT: Using the following from my package.json:

    "contentlayer": "0.3.1",
    "next": "13.3.0",
    "next-contentlayer": "0.3.1",
Perjan commented 1 year ago

Local fix until this issue is resolved. You can update the dev script in package.json and make use of the content layer cli as follows:

"scripts": {
    "dev": "contentlayer dev & next dev"
}

then run pnpm dev

Content layer cli - https://www.contentlayer.dev/docs/reference/cli#dev

This worked for me as well.

weleo commented 1 year ago

Local fix until this issue is resolved. You can update the dev script in package.json and make use of the content layer cli as follows:

"scripts": {
    "dev": "contentlayer dev & next dev"
}

then run pnpm dev

Content layer cli - contentlayer.dev/docs/reference/cli#dev

Little side note: Due to how &works, contentlayer dev & next devruns concurrently on macOS and Linux, but for example, runs sequentially in PowerShell. So if you need consistency for this edge case, you may want to go with concurrently \"contentlayer dev\" \"next dev\".

schickling commented 1 year ago

This should be addressed with the 0.3.2 release. πŸŽ‰

abheektripathy commented 1 year ago

im not sure, as to open a new issue for this but the problem was the same as mentioned though here's a catch, i was able to generate the .contentlayer folder but now my app's stuck here, i don't see anything at post 3000, it just loads infinitely. Any help appreciated!

Screenshot 2023-06-12 at 11 54 04 PM

here's my next.config.js

const { withContentlayer } = require('next-contentlayer')
/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
    images: {
        unoptimized: true,
      },
}

module.exports = withContentlayer(nextConfig)

and my contentlayer.config.ts

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

export const Post = defineDocumentType(() => ({
  name: 'Post',
  filePathPattern: `**/*.md`,
  fields: {
    title: { type: 'string', required: true },
    date: { type: 'date', required: true },
  },
  computedFields: {
    url: { type: 'string', resolve: (post) => `/posts/${post._raw.flattenedPath}` },
  },
}))

export default makeSource({ contentDirPath: 'posts', documentTypes: [Post] })

and my packages

    "contentlayer": "^0.3.3",
    "date-fns": "^2.30.0",
    "next": "13.4.4",
    "next-contentlayer": "^0.3.3",
weijunext commented 1 year ago

work fine with these configs( see my forked example ):

 "next": "13.2.4",
 "next-contentlayer": "0.3.1",
"contentlayer": "0.3.1"

It works. Thank you!

saifookhan commented 1 year ago

Also works with πŸš€

"contentlayer": "0.3.3",
"next": "13.3.0",
"next-contentlayer": "0.3.3"
konsalex commented 1 year ago

Still having the same issue with versions 0.3.1 and 0.3.3 and the behaviour is quite flaky, as it worked and then suddenly stopped working so not sure exactly the reason behind it.

weijunext commented 1 year ago

Still having the same issue with versions 0.3.1 and 0.3.3 and the behaviour is quite flaky, as it worked and then suddenly stopped working so not sure exactly the reason behind it.

try removing the remark plugin from the contentlayer.config.js file, like this:

export default makeSource({
  contentDirPath: './content',
  documentTypes: [Post],
  mdx: {
    remarkPlugins: [remarkGfm], // only one, no more remark plugins
  },
})

You aslo can look at the contentlayer.config.js and package.json in my project: https://github.com/weijunext/nextjs-learn-demos/tree/contentlayer

konsalex commented 1 year ago

@weijunext remark is not even included. Should it be?

konsalex commented 1 year ago

After investigation, I suspect that it has to do something with orphan processes staying in the background? Not entirely sure, but after closing iTerm, both iTerm, WebStorm and VSCode servers started working as expected πŸ€”

Reference also to here: https://github.com/shadcn-ui/taxonomy/issues/122

tanishbaansal commented 1 year ago

Simply going to cd apps/www/ and doing npm run build generated the content layer generated folder for me

image
aloptrbl commented 8 months ago

my only solution is put the .md files in data folder data/posts/post-1.md Screenshot 2024-03-08 at 7 02 58β€―AM

work on latest version of next.js "dependencies": { "contentlayer": "^0.3.4", "next": "latest", "next-contentlayer": "^0.3.4", }