I am looking to setup contentlayer in a design-system monorepo using npm workspaces with the following folder structure:
- docs [NextJS docs site]
- components
- component-1
- README.md
- component-2
- README.md
- component-3
- README.md
Ideally contentlayer would be installed and have its configuration in the docs folder, but would look for content files relative to the root directory so it can reach the components folder (in the real example there are other folders in the root that will also have documentation). The npm commands would also be run from the root folder.
I've tried a few different setups and got different results, from error messages to no error but not being able to find documents to process.
Setup 1 - using the -c flag to specify config location
Here I'm running a specific contentlayer build command and specifying the config path. This setup throws an "An unchecked error was produced." error.
Repo with reproduction: https://github.com/BarnabyBishop/contentlayer-monorepo-bug
To setup run the following in the project root:
npm i
npm run contentlayer
makeSource config:
export default makeSource({
contentDirInclude: ["components"],
contentDirPath: ".",
documentTypes: [Component],
onUnknownDocuments: "skip-ignore",
});
Error received:
➜ npm run contentlayer
> content-layer-test@1.0.0 contentlayer
> npm run contentlayer --workspace=docs
> docs@0.1.0 contentlayer
> contentlayer build -c './docs/contentlayer.config.ts'
This error shouldn't have happened. Please consider opening a GitHub issue with the stack trace below here:
https://github.com/contentlayerdev/contentlayer/issues
An unchecked error was produced.
Error: All path segments except the first are expected to be relative, got /Users/user/projects/content-layer-test,/Users/user/projects/content-layer-test/components/component-1/README.md
at filePathJoin (file:///Users/user/projects/content-layer-test/node_modules/@contentlayer/utils/src/file-paths.ts:78:13)
at next (file:///Users/user/projects/content-layer-test/node_modules/@contentlayer/source-files/src/fetchData/makeCacheItemFromFilePath.ts:42:28)
at Generator.next (<anonymous>)
at ISuspend.factory (file:///Users/user/projects/content-layer-test/node_modules/@effect-ts/system/_src/Effect/gen.ts:135:28)
at FiberContext.evaluateNow (file:///Users/user/projects/content-layer-test/node_modules/@effect-ts/system/_src/Fiber/context.ts:1173:51)
at file:///Users/user/projects/content-layer-test/node_modules/@effect-ts/system/_src/Fiber/context.ts:576:33
at file:///Users/user/projects/content-layer-test/node_modules/@effect-ts/system/_src/Support/Scheduler/index.ts:15:9
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Fiber: #30 (started at: 2022-08-22T02:28:18.622Z) was supposed to continue to:
a future continuation at packages/@contentlayer/source-files/src/fetchData/makeCacheItemFromFilePath.ts:111:15
Fiber: #30 (started at: 2022-08-22T02:28:18.622Z) Execution trace:
packages/@contentlayer/source-files/src/fetchData/makeCacheItemFromFilePath.ts:41:10
Fiber: #30 (started at: 2022-08-22T02:28:18.622Z) was spawned by:
Fiber: #20 (started at: 2022-08-22T02:28:18.611Z) was supposed to continue to:
a future continuation at packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:66:16
a future continuation at packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:67:16
a future continuation at packages/@contentlayer/source-files/src/fetchData/index.ts:102:21
Fiber: #20 (started at: 2022-08-22T02:28:18.611Z) Execution trace:
packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:55:24
packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:52:49
packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:121:10
packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:117:22
packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:46:44
packages/@contentlayer/source-files/src/fetchData/fetchAllDocuments.ts:45:10
Fiber: #20 (started at: 2022-08-22T02:28:18.611Z) was spawned by:
Fiber: #16 (started at: 2022-08-22T02:28:18.610Z) was supposed to continue to: <empty trace>
Fiber: #16 (started at: 2022-08-22T02:28:18.610Z) Execution trace: <empty trace>
Fiber: #16 (started at: 2022-08-22T02:28:18.610Z) was spawned by:
Fiber: #15 (started at: 2022-08-22T02:28:18.610Z) was supposed to continue to: <empty trace>
Fiber: #15 (started at: 2022-08-22T02:28:18.610Z) Execution trace: <empty trace>
Fiber: #15 (started at: 2022-08-22T02:28:18.610Z) was spawned by:
Fiber: #14 (started at: 2022-08-22T02:28:18.606Z) was supposed to continue to: <empty trace>
Fiber: #14 (started at: 2022-08-22T02:28:18.606Z) Execution trace:
packages/@contentlayer/source-files/src/fetchData/index.ts:54:116
packages/@contentlayer/utils/src/node/fs.ts:89:15
packages/@contentlayer/utils/src/node/fs.ts:88:72
packages/@contentlayer/utils/src/node/fs.ts:88:12
packages/@contentlayer/utils/src/node/fs.ts:16:10
packages/@contentlayer/utils/src/node/fs.ts:15:60
packages/@contentlayer/utils/src/node/fs.ts:15:15
packages/@contentlayer/utils/src/node/fs.ts:30:27
packages/@contentlayer/core/src/DataCache.ts:50:31
packages/@contentlayer/core/src/DataCache.ts:49:17
packages/@contentlayer/core/src/ArtifactsDir.ts:31:12
packages/@contentlayer/core/src/cwd.ts:24:43
packages/@contentlayer/utils/src/node/version.ts:21:15
packages/@contentlayer/utils/src/node/version.ts:20:10
packages/@contentlayer/utils/src/node/fs.ts:76:17
packages/@contentlayer/utils/src/node/fs.ts:75:12
packages/@contentlayer/utils/src/node/fs.ts:44:22
packages/@contentlayer/core/src/ArtifactsDir.ts:27:15
packages/@contentlayer/core/src/DataCache.ts:46:38
packages/@contentlayer/core/src/DataCache.ts:45:12
Fiber: #14 (started at: 2022-08-22T02:28:18.606Z) was spawned by:
Fiber: #1 (started at: 2022-08-22T02:28:18.529Z) was supposed to continue to: <empty trace>
Fiber: #1 (started at: 2022-08-22T02:28:18.529Z) Execution trace:
packages/@contentlayer/core/src/cwd.ts:24:43
packages/@contentlayer/core/src/generation/generate-dotpkg.ts:82:13
packages/@contentlayer/core/src/generation/generate-dotpkg.ts:78:16
packages/@contentlayer/cli/src/commands/BuildCommand.ts:26:14
packages/@contentlayer/cli/src/commands/BuildCommand.ts:25:91
packages/@contentlayer/cli/src/commands/BuildCommand.ts:25:12
packages/@contentlayer/core/src/getConfig/index.ts:41:18
packages/@contentlayer/core/src/getConfig/index.ts:40:10
packages/@contentlayer/core/src/getConfig/esbuild.ts:47:15
packages/@contentlayer/core/src/getConfig/esbuild.ts:39:26
packages/@contentlayer/core/src/getConfig/esbuild.ts:37:12
packages/@contentlayer/core/src/getConfig/esbuild.ts:117:12
packages/@contentlayer/core/src/getConfig/esbuild.ts:75:36
packages/@contentlayer/core/src/getConfig/index.ts:197:13
packages/@contentlayer/core/src/getConfig/index.ts:186:28
packages/@contentlayer/core/src/getConfig/index.ts:184:44
packages/@contentlayer/core/src/getConfig/index.ts:171:28
packages/@contentlayer/core/src/getConfig/index.ts:169:31
packages/@contentlayer/core/src/getConfig/index.ts:156:28
packages/@contentlayer/core/src/getConfig/index.ts:154:15
packages/@contentlayer/core/src/getConfig/index.ts:151:15
packages/@contentlayer/core/src/getConfig/index.ts:150:15
packages/@contentlayer/core/src/cwd.ts:24:43
packages/@contentlayer/core/src/getConfig/index.ts:135:27
packages/@contentlayer/core/src/getConfig/index.ts:122:10
Fiber: #1 (started at: 2022-08-22T02:28:18.529Z) was spawned by: <empty trace>
OS: darwin 21.6.0 (arch: arm64)
Process: /Users/user/.nvm/versions/node/v16.14.0/bin/node /Users/user/projects/content-layer-test/node_modules/.bin/contentlayer build -c ./docs/contentlayer.config.ts
Node version: v16.14.0
Contentlayer version: 0.2.7
npm ERR! Lifecycle script `contentlayer` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: docs@0.1.0
npm ERR! at location: /Users/user/projects/content-layer-test/docs
Setup 2 - using useContentLayer hook & relative paths
The idea here is rather than specifying the config path as the previous implementation, use the useContentLayer NextJS hook but change the makeSource config look to the root folder for directories, and set the NextJS site's dev script with the following to find the contentlayer config:
"dev": "INIT_CWD=$PWD next dev",
This one doesn't throw any errors, but gets Generated 0 documents in .contentlayer
Repo with reproduction: https://github.com/BarnabyBishop/contentlayer-monorepo-bug/tree/relative
Run the following commands in the root folder:
Component's filePathPattern:
filePathPattern: "components/**/README.md",
makeSource config:
export default makeSource({
contentDirInclude: ["components"],
contentDirPath: "..",
documentTypes: [Component],
onUnknownDocuments: "skip-ignore",
});
I've tried various filePathPattern options to no avail such as ../components/**/README.md, ./components/**/README.md or even **/README.md.
I also tried a few other setups such as:
- Moving
contentlayer.config.ts to the root directory.
- Removing the
contentDirInclude path which gets too greedy and tries to load a lot of content from node_modules
- Various different path globs for
contentDirInclude and contentDirPath.
Any ideas on a config that might get this working would be appreciated. 👍
I am looking to setup
contentlayerin a design-system monorepo using npm workspaces with the following folder structure:Ideally
contentlayerwould be installed and have its configuration in the docs folder, but would look for content files relative to the root directory so it can reach thecomponentsfolder (in the real example there are other folders in the root that will also have documentation). Thenpmcommands would also be run from the root folder.I've tried a few different setups and got different results, from error messages to no error but not being able to find documents to process.
Setup 1 - using the
-cflag to specify config locationHere I'm running a specific
contentlayer buildcommand and specifying the config path. This setup throws an "An unchecked error was produced." error.Repo with reproduction: https://github.com/BarnabyBishop/contentlayer-monorepo-bug
To setup run the following in the project root:
makeSourceconfig:Error received:
Setup 2 - using useContentLayer hook & relative paths
The idea here is rather than specifying the config path as the previous implementation, use the
useContentLayerNextJS hook but change themakeSourceconfig look to the root folder for directories, and set the NextJS site's dev script with the following to find thecontentlayerconfig:This one doesn't throw any errors, but gets
Generated 0 documents in .contentlayerRepo with reproduction: https://github.com/BarnabyBishop/contentlayer-monorepo-bug/tree/relative
Run the following commands in the root folder:
Component's filePathPattern:
makeSourceconfig:I've tried various
filePathPatternoptions to no avail such as../components/**/README.md,./components/**/README.mdor even**/README.md.I also tried a few other setups such as:
contentlayer.config.tsto the root directory.contentDirIncludepath which gets too greedy and tries to load a lot of content fromnode_modulescontentDirIncludeandcontentDirPath.Any ideas on a config that might get this working would be appreciated. 👍