contentlayerdev / website

Contentlayer Website
https://www.contentlayer.dev
MIT License
129 stars 62 forks source link

next.js build: building contentlayer prior to TSC or adding more clear docs #105

Open jzxhuang opened 1 year ago

jzxhuang commented 1 year ago

When following the official Getting Started example for Next.js, the app fails to build on CI or any environemnt where .contentlayer doesn't exist already.

This appears to be because TSC runs prior to contentlayer, which errors out.

I'm not sure if this can be changed at all (to run a Next plugin prior to the TSC step). That would seem like the ideal solution, but otherwise, would be great to update the documentation & examples to modify the build step

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

I'm happy to make a PR to help out, just wanted to check if this is indeed an issue that others experience or if I'm really missing something basic

shaneafsar commented 1 year ago

Just adding a comment that we've had to do the same thing for our site. We also have to use concurrently for running both contentlayer and next in dev mode.

seancdavis commented 1 year ago

@jzxhuang Where would you expect to see this documentation?

Perhaps a mention in the getting started guide and also a note in Known Problems or maybe a separate troubleshooting page?

seancdavis commented 1 year ago

@shaneafsar Can you say more about your development setup?

jzxhuang commented 1 year ago

@jzxhuang Where would you expect to see this documentation?

Perhaps a mention in the getting started guide and also a note in Known Problems or maybe a separate troubleshooting page?

Yeah, I would expect it in the Getting Started guide — probably under "next.js configuration" or a new section like "Building for Production" or something like that. Also adding a note in Known Problems is a great idea!

btw, happy to make a PR for this — I just wanted to first confirm that it's a known issue with any easy solutions, and not just something I'm missing 😅

shaneafsar commented 1 year ago

@shaneafsar Can you say more about your development setup?

  • What errors were you running into?
  • How did concurrently fix those errors?
  • Why did you choose concurrently over other options for this type of behavior?

We followed a recommendation from this issue: https://github.com/contentlayerdev/contentlayer/issues/415#issuecomment-1503658563

Some info about our setup:

It's been awhile, but we ran into the missing .contentlayer folder issue. Once the folder was created, it seemed to work properly and we could go back to using the recommended approach, but people pulling down the repo for the first time would encounter the issue. (There was another dev who had an infinite reload issue, but we hadn't narrowed that down).

We'll try the recommended way in a couple sprints to see if the issue is still happening, and try to provide more detailed reproduction steps from there.