Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running contentlayer build #25

Open
ktroach opened this issue Mar 9, 2024 · 1 comment
Open

Error when running contentlayer build #25

ktroach opened this issue Mar 9, 2024 · 1 comment

Comments

@ktroach
Copy link

ktroach commented Mar 9, 2024

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
Copy link
Author

ktroach commented Mar 9, 2024

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

arcanis/clipanion#158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant