Open samchouse opened 1 year ago
I just ran a build on Vercel and it seems like there is no error there, not sure what's going on.
Thanks for opening this issue. Can you please provide minimal a reproduction repo with instructions how to reproduce the problem you're experiencing? Thank you!
yarn install
yarn contentlayer build
I couldn't reproduce the problem you've described:
Seems like something was deprecated on Node 19, and removed in Node 20, which is where the issue lies.
cl-demo on main [!] via v20.3.1 took 22s
❯ rtx use node@18
Downloading node-v18.16.1-linux-x64.tar.gz...
-> https://nodejs.org/dist/v18.16.1/node-v18.16.1-linux-x64.tar.gz
Installing node-v18.16.1-linux-x64...
Installed node-v18.16.1-linux-x64 to /home/xenfo/.local/share/rtx/installs/node/18.16.1
rtx node@18.16.1 9.5.1 ✓ 15s
cl-demo on main [!?] via v18.16.1 took 15s
❯ npm i -g
cl-demo on main [!?] via v18.16.1
❯ node -v
v18.16.1
cl-demo on main [!?] via v18.16.1
❯ npm i -g yarn
added 1 package in 474ms
Reshimming rtx 18.16.1...
cl-demo on main [!?] via v18.16.1
❯ yarn
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 217ms
➤ YN0000: ┌ Link step
➤ YN0008: │ esbuild@npm:0.17.19 must be rebuilt because its dependency tree changed
➤ YN0008: │ protobufjs@npm:7.2.3 must be rebuilt because its dependency tree changed
➤ YN0008: │ contentlayer@npm:0.3.3 must be rebuilt because its dependency tree changed
➤ YN0000: └ Completed in 1s 257ms
➤ YN0000: Done in 1s 650ms
cl-demo on main [!?] via v18.16.1 took 2s
❯ yarn contentlayer build
Generated 1 documents in .contentlayer
cl-demo on main [!?] via v18.16.1
❯ rtx use node@19
Downloading node-v19.9.0-linux-x64.tar.gz...
-> https://nodejs.org/dist/v19.9.0/node-v19.9.0-linux-x64.tar.gz
WARNING: node-v19.9.0-linux-x64 is in LTS Maintenance mode and nearing its end of life.
It only receives *critical* security updates, *critical* bug fixes and documentation updates.
Installing node-v19.9.0-linux-x64...
Installed node-v19.9.0-linux-x64 to /home/xenfo/.local/share/rtx/installs/node/19.9.0
rtx node@19.9.0 9.6.3 ✓ 13s
cl-demo on main [!?] via v19.9.0 took 12s
❯ npm i -g yarn
added 1 package in 339ms
Reshimming rtx 19.9.0...
cl-demo on main [!?] via v19.9.0
❯ yarn contentlayer build
Generated 1 documents in .contentlayer
(node:115156) [DEP0164] DeprecationWarning: Implicit coercion to integer for exit code is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
cl-demo on main [!?] via v19.9.0
❯ rtx use node@20
cl-demo on main [!?] via v20.3.1
❯ yarn
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0008: │ esbuild@npm:0.17.19 must be rebuilt because its dependency tree changed
➤ YN0008: │ protobufjs@npm:7.2.3 must be rebuilt because its dependency tree changed
➤ YN0008: │ contentlayer@npm:0.3.3 must be rebuilt because its dependency tree changed
➤ YN0000: └ Completed in 1s 27ms
➤ YN0000: Done in 1s 368ms
cl-demo on main [!?] via v20.3.1
❯ yarn contentlayer build
Generated 1 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 (/tmp/cl-demo/node_modules/clipanion/lib/advanced/Cli.js:232:26)
at run (file:///tmp/cl-demo/node_modules/@contentlayer/cli/src/index.ts:39:3)
at main (/tmp/cl-demo/node_modules/contentlayer/bin/cli.cjs:5:3) {
code: 'ERR_INVALID_ARG_TYPE'
}
cl-demo on main [!?] via v20.3.1
❯
(node:115156) [DEP0164] DeprecationWarning: Implicit coercion to integer for exit code is deprecated.
I still couldn't reproduce it via GitPod.
I’m not sure what’s going on with GitPod but I was able to reproduce this on two separate machines, one in WSL and the other being a Mac.
Just reproduced on GitPod too
@Xenfo, hey, did you solve this somehow?
@Xenfo, hey, did you solve this somehow?
No, it’s annoying but I just let it happen since everything is still generated properly.
Same here - issue occuring on Node v20.5.0. DOES NOT occur with Node 18.17.
I have the same issue Node v20.5.1 Switching to Node v18.17.1 did do the trick
Same problem here. Not sure if there is anything to do about it.
This is related to Node Deprecation DEP0164 (process.exit(code), process.exitCode coercion to integer.
This will offer a deprecation warning on Node 19.x.x, but as of Node 20.0.0, it will throw an error.
In relation to contentlayer, the CLI is attempting to assign a resulting object with documentCount
's existence as a means of coercing to a positive exit code.
Within CLI.js function runExit
, assignment to process.exitCode
should be a valid integer.
It is worth noting that this doesn't affect functionality of CLI commands. It just impacts the ability for CLI commands to report a valid exit code, so it will always be assumed to be an error.
Hello, same problem here. This error message is confusing: I thought I had done something wrong in my Contentlayer configuration file.
Thank you all for your investigations.
Hello, same problem here. This error message is confusing: I thought I had done something wrong in my Contentlayer configuration file.
Thank you all for your investigations.
Me too. I just upgrade my node to v20.9.0
, and this happen.
I think i should downgrade again.
Hello, same problem here. This error message is confusing: I thought I had done something wrong in my Contentlayer configuration file. Thank you all for your investigations.
Me too. I just upgrade my node to
v20.9.0
, and this happen. I think i should downgrade again.
No, don't worry. Even if the error message occurs, the code runs...
It's just very confusing.
So it seems the BuildCommand
has been yielding an object (of type GenerateInfo
) to clipanion's Cli#runExit
API which instead expects an exit code number
.
I suspect this has gone unnoticed for so long due to the now legacy process.exitCode
coercion behavior in Node.js. I will open a PR with my attempt at a fix, but I've also applied it as a patch via Yarn for now.
Here's what the patch looks like using yarn patch
:
.yarn/patches/@contentlayer-cli-npm-0.3.3-e932de1bc4.patch
diff --git a/dist/commands/BuildCommand.js b/dist/commands/BuildCommand.js
index 1cc67c8c9b28622c2391c1da70754ab99dcc35d6..27b35388b71bc8cb64463329e9b1ef251b3382b4 100644
--- a/dist/commands/BuildCommand.js
+++ b/dist/commands/BuildCommand.js
@@ -4,7 +4,7 @@ import { BaseCommand } from './_BaseCommand.js';
class BuildCommand extends BaseCommand {
constructor() {
super(...arguments);
- this.executeSafe = () => pipe(this.clearCacheIfNeeded(), T.chain(() => core.getConfig({ configPath: this.configPath })), T.tap((config) => (config.source.options.disableImportAliasWarning ? T.unit : T.fork(core.validateTsconfig))), T.chain((config) => core.generateDotpkg({ config, verbose: this.verbose })), T.tap(core.logGenerateInfo), OT.withSpan('@contentlayer/cli/commands/BuildCommand:executeSafe'));
+ this.executeSafe = () => pipe(this.clearCacheIfNeeded(), T.chain(() => core.getConfig({ configPath: this.configPath })), T.tap((config) => (config.source.options.disableImportAliasWarning ? T.unit : T.fork(core.validateTsconfig))), T.chain((config) => core.generateDotpkg({ config, verbose: this.verbose })), T.tap(core.logGenerateInfo), T.map(() => 0), OT.withSpan('@contentlayer/cli/commands/BuildCommand:executeSafe'));
}
}
BuildCommand.paths = [['build']];
still getting this error +1
also just got this error running node v20 +1
Issue goes away on node version 18
In case y'all missed it, the official recommendation from those working with @schickling to keep this project going is to temporarily switch to the contentlayer2 fork while they sort out the longer-term plan for continued support of this project.
My fix for this issue was merged over there and released in 0.4.5 on the fork.
📝 I wrote some documentation to help anyone else moving over to the fork here. (https://github.com/timlrx/contentlayer2/pull/18)
See:
Follow:
The error is non-fatal and still generates the documents.
Contentlayer config: