shadcn / next-contentlayer

A template with Next.js 13 app dir, Contentlayer, Tailwind CSS and dark mode.
https://next-contentlayer.vercel.app
678 stars 91 forks source link

Error when running contentlayer build #25

Open ktroach opened 6 months ago

ktroach commented 6 months ago

First off, this is not an issue with this repo, but the repo is affected by a bug in a dependency that it uses, and wanted to bring awareness to it here, in case someone else runs into this.

I was getting this error in my own project, which uses contentlayer, so I decided to clone this project to see if I could replicate it and I could indeed.

Warning: Contentlayer might not work as expected on Windows
Generated 5 documents in .contentlayer
TypeError: The "code" argument must be of type number. Received an instance of Object
    at process.set [as exitCode] (node:internal/bootstrap/node:124:9)
    at Cli.runExit (C:\Users\wayof\Developments\next-contentlayer\node_modules\clipanion\lib\advanced\Cli.js:232:26)  
    at run (file:///C:/Users/wayof/Developments/next-contentlayer/node_modules/@contentlayer/cli/src/index.ts:39:3)   
    at main (C:\Users\wayof\Developments\next-contentlayer\node_modules\contentlayer\bin\cli.cjs:5:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

This error was very frustrating to say the least, and while it is not directly breaking contentlayer's build (mdx's still get processed and generate content), it does cause an error.

I tracked down the offending code from the stack trace here: next-contentlayer\node_modules\clipanion\lib\advanced\Cli.js:232:26

    async runExit(input, context) {
        process.exitCode = await this.run(input, context);
    }

In my project, I am using a contentlayer:build script, and it was happening only on the build and not when in dev mode.

It is probably fairly obvious what is causing this. It is expecting a number type but getting something else like an object. I debugged it locally and here is the result:

    async runExit(input, context) {
        const result = await this.run(input, context);
        console.log(">>>> result >>> ", result);
        process.exitCode = 0;
    }

Here is the actual output from the change I made locally:

Warning: Contentlayer might not work as expected on Windows
Generated 5 documents in .contentlayer
>>>> result >>>  { documentCount: 5 }

Instead of returning a number, clipanion is returning an object. This issue is happening pretty much on everything that is using contentlayer build as far as I am aware

I am not sure if I should submit a pull request to clipanion since I have a fix or not. And actually, I should probably report the issue on the clipanion repo.

ktroach commented 6 months ago

Since this error is caused in a downstream library, not from this project, I reported the issue on that library's repo:

https://github.com/arcanis/clipanion/issues/158