[GH-ISSUE #57] Error: process.stdout.cursorTo is not a function #30

Closed
opened 2026-03-03 13:52:20 +03:00 by kerem · 9 comments
Owner

Originally created by @sandiwp on GitHub (Aug 24, 2024).
Original GitHub issue: https://github.com/jehna/humanify/issues/57

echo "OPENAI_API_KEY=api key..." > .env && humanify openai main.js
export OPENAI_API_KEY="api key..." && humanify openai main.js
OPENAI_TOKEN=api key... humanify openai main.js
humanify --apiKey="api key..." main.js
file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67
process.stdout.cursorTo(0);
^

TypeError: process.stdout.cursorTo is not a function
at showPercentage (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67:20)
at visitAllIdentifiers (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56606:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56720:12
at async unminify (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:196:27)
at async Command. (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56790:3)

Node.js v20.17.0
file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67
process.stdout.cursorTo(0);
^

TypeError: process.stdout.cursorTo is not a function
at showPercentage (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67:20)
at visitAllIdentifiers (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56606:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56720:12
at async unminify (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:196:27)
at async Command. (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56790:3)

Node.js v20.17.0
file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67
process.stdout.cursorTo(0);
^

TypeError: process.stdout.cursorTo is not a function
at showPercentage (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67:20)
at visitAllIdentifiers (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56606:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56720:12
at async unminify (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:196:27)
at async Command. (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56790:3)

Node.js v20.17.0
error: unknown option '--apiKey=api key...'

Usage: humanify [options] [command]

Unminify code using OpenAI's API or a local LLM

Originally created by @sandiwp on GitHub (Aug 24, 2024). Original GitHub issue: https://github.com/jehna/humanify/issues/57 echo "OPENAI_API_KEY=api key..." > .env && humanify openai main.js export OPENAI_API_KEY="api key..." && humanify openai main.js OPENAI_TOKEN=api key... humanify openai main.js humanify --apiKey="api key..." main.js file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67 process.stdout.cursorTo(0); ^ TypeError: process.stdout.cursorTo is not a function at showPercentage (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67:20) at visitAllIdentifiers (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56606:35) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56720:12 at async unminify (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:196:27) at async Command.<anonymous> (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56790:3) Node.js v20.17.0 file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67 process.stdout.cursorTo(0); ^ TypeError: process.stdout.cursorTo is not a function at showPercentage (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67:20) at visitAllIdentifiers (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56606:35) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56720:12 at async unminify (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:196:27) at async Command.<anonymous> (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56790:3) Node.js v20.17.0 file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67 process.stdout.cursorTo(0); ^ TypeError: process.stdout.cursorTo is not a function at showPercentage (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:67:20) at visitAllIdentifiers (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56606:35) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56720:12 at async unminify (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:196:27) at async Command.<anonymous> (file:///C:/Users/Rahim/AppData/Roaming/npm/node_modules/humanifyjs/dist/index.mjs:56790:3) Node.js v20.17.0 error: unknown option '--apiKey=api key...' Usage: humanify [options] [command] Unminify code using OpenAI's API or a local LLM
kerem 2026-03-03 13:52:20 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jehna commented on GitHub (Aug 24, 2024):

Which environment are you running humanify on? It seems that your terminal/stdout/something does not support clearing the row.
You should be able to fix this for now by using --verbose flag, which disables the clearing. I'll fix the underlying issue in coming versions.

<!-- gh-comment-id:2308365861 --> @jehna commented on GitHub (Aug 24, 2024): Which environment are you running humanify on? It seems that your terminal/stdout/something does not support clearing the row. You should be able to fix this for now by using `--verbose` flag, which disables the clearing. I'll fix the underlying issue in coming versions.
Author
Owner

@jehna commented on GitHub (Aug 24, 2024):

And thank you for reporting the issue! 🙇

<!-- gh-comment-id:2308366266 --> @jehna commented on GitHub (Aug 24, 2024): And thank you for reporting the issue! 🙇
Author
Owner

@sandiwp commented on GitHub (Aug 24, 2024):

Thank you very much for your support

It worked fine when I used it before and now it doesn't work

Another thing I know is that I did console.log in different places but it doesn't display in the command lines but they are executing as far as I understand.

<!-- gh-comment-id:2308386804 --> @sandiwp commented on GitHub (Aug 24, 2024): Thank you very much for your support It worked fine when I used it before and now it doesn't work Another thing I know is that I did console.log in different places but it doesn't display in the command lines but they are executing as far as I understand.
Author
Owner

@jehna commented on GitHub (Aug 25, 2024):

I checked into this more. Is it possible by any chance that you're trying to run humanify using an old node.js? It seems that stdout.cursorTo is introduced in node.js version 17, so this implies that your node.js version would have been under that. I confused that previously with stdout.clearLine, which would be absent in weird terminal environments

<!-- gh-comment-id:2308773730 --> @jehna commented on GitHub (Aug 25, 2024): I checked into this more. Is it possible by any chance that you're trying to run humanify using an old node.js? It seems that `stdout.cursorTo` is introduced in node.js version 17, so this implies that your node.js version would have been under that. I confused that previously with `stdout.clearLine`, which would be absent in weird terminal environments
Author
Owner

@jehna commented on GitHub (Aug 25, 2024):

You can check via node --version

<!-- gh-comment-id:2308773848 --> @jehna commented on GitHub (Aug 25, 2024): You can check via `node --version`
Author
Owner

@jehna commented on GitHub (Oct 18, 2024):

Closing due inactivity

<!-- gh-comment-id:2423236447 --> @jehna commented on GitHub (Oct 18, 2024): Closing due inactivity
Author
Owner

@ItsHarper commented on GitHub (Jul 24, 2025):

process.stdout.cursorTo is only defined when the shell you're running in isn't capturing the output. You need to check process.stdout.isTTY before trying to access it.

Source:
https://nodejs.org/api/process.html#a-note-on-process-io
https://nodejs.org/api/tty.html#writestreamcursortox-y-callback

<!-- gh-comment-id:3111924889 --> @ItsHarper commented on GitHub (Jul 24, 2025): `process.stdout.cursorTo` is only defined when the shell you're running in isn't capturing the output. You need to check `process.stdout.isTTY` before trying to access it. Source: https://nodejs.org/api/process.html#a-note-on-process-io https://nodejs.org/api/tty.html#writestreamcursortox-y-callback
Author
Owner

@0xdevalias commented on GitHub (Jul 27, 2025):

process.stdout.cursorTo is only defined when the shell you're running in isn't capturing the output. You need to check process.stdout.isTTY before trying to access it.

Is it possible by any chance that you're trying to run humanify using an old node.js? It seems that stdout.cursorTo is introduced in node.js version 17, so this implies that your node.js version would have been under that.

Based on the above, we can see this behaviour in node v22, so it wasn't just an issue with running an older version of node:

⇒ node --version
v22.16.0
⇒ node -p -e "Boolean(process.stdout.isTTY)"
true

⇒ node -p -e "Boolean(process.stdout.isTTY)" | cat
false
⇒ node -p -e "process.stdout.cursorTo(0)"
true

⇒ node -p -e "process.stdout.cursorTo(0)" | cat
[eval]:1
process.stdout.cursorTo(0)
               ^

TypeError: process.stdout.cursorTo is not a function
    at [eval]:1:16
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:449:12
    at [eval]-wrapper:6:24
    at runScriptInContext (node:internal/process/execution:447:60)
    at evalFunction (node:internal/process/execution:87:30)
    at evalScript (node:internal/process/execution:99:3)
    at node:internal/main/eval_string:74:3

Node.js v22.16.0

I'll fix the underlying issue in coming versions.

@jehna So this is still a valid issue that should be fixed, and this issue should be re-opened to track that.

Usage:

github.com/jehna/humanify@7beba2d324/src/progress.ts (L25-L31)

Example of a potential fix:

export function showPercentage(percentage: number) {
  const percentageStr = Math.round(percentage * 100);

  const canUseCursorOps = process.stdout.isTTY
    && typeof process.stdout.clearLine === "function"
    && typeof process.stdout.cursorTo === "function";

  if (!verbose.enabled && canUseCursorOps) {
    process.stdout.clearLine(0);
    process.stdout.cursorTo(0);
    process.stdout.write(`Processing: ${percentageStr}%`);
  } else {
    verbose.log(`Processing: ${percentageStr}%`);
  }

  if (percentage === 1 && canUseCursorOps) {
    process.stdout.write("\n");
  }
}

Ideally a similar more explicit fix would be added to clearLine in showProgress as well, instead of just relying on the optional chaining syntax.


You can see that this would also be an issue with process.stdout.clearLine:

⇒ node -p -e "process.stdout.clearLine(0)" | cat
[eval]:1
process.stdout.clearLine(0)
               ^

TypeError: process.stdout.clearLine is not a function
    at [eval]:1:16
    at runScriptInThisContext (node:internal/vm:209:10)
    at node:internal/process/execution:449:12
    at [eval]-wrapper:6:24
    at runScriptInContext (node:internal/process/execution:447:60)
    at evalFunction (node:internal/process/execution:87:30)
    at evalScript (node:internal/process/execution:99:3)
    at node:internal/main/eval_string:74:3

Node.js v22.16.0

Except that in the code, you're calling process.stdout.clearLine with the optional chaining syntax like this:

github.com/jehna/humanify@7beba2d324/src/progress.ts (L10)

github.com/jehna/humanify@7beba2d324/src/progress.ts (L28)

Whereas for process.stdout.cursorTo you're not using the optional chaining syntax:

github.com/jehna/humanify@7beba2d324/src/progress.ts (L29)

Looking at the git blame / history, the progress feature seemed to be first added in 70e31966e4 on Aug 9, 2024, and neither used the optional chaining syntax:

But then the optional chaining was added to clearLine in 05b6a8e261 on Aug 9, 2024 as it broke the CI:

<!-- gh-comment-id:3123626842 --> @0xdevalias commented on GitHub (Jul 27, 2025): > `process.stdout.cursorTo` is only defined when the shell you're running in isn't capturing the output. You need to check `process.stdout.isTTY` before trying to access it. - https://nodejs.org/api/process.html#a-note-on-process-io - > To check if a stream is connected to a [TTY](https://nodejs.org/api/tty.html#tty) context, check the `isTTY` property. - https://nodejs.org/api/tty.html - > When Node.js detects that it is being run with a text terminal ("TTY") attached, [`process.stdin`](https://nodejs.org/api/process.html#processstdin) will, by default, be initialized as an instance of `tty.ReadStream` and both [`process.stdout`](https://nodejs.org/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/api/process.html#processstderr) will, by default, be instances of `tty.WriteStream`. The preferred method of determining whether Node.js is being run within a TTY context is to check that the value of the `process.stdout.isTTY` property is `true` > Is it possible by any chance that you're trying to run humanify using an old node.js? It seems that `stdout.cursorTo` is introduced in node.js version 17, so this implies that your node.js version would have been under that. Based on the above, we can see this behaviour in node v22, so it wasn't just an issue with running an older version of node: ```shell ⇒ node --version v22.16.0 ``` ```shell ⇒ node -p -e "Boolean(process.stdout.isTTY)" true ⇒ node -p -e "Boolean(process.stdout.isTTY)" | cat false ``` ```shell ⇒ node -p -e "process.stdout.cursorTo(0)" true ⇒ node -p -e "process.stdout.cursorTo(0)" | cat [eval]:1 process.stdout.cursorTo(0) ^ TypeError: process.stdout.cursorTo is not a function at [eval]:1:16 at runScriptInThisContext (node:internal/vm:209:10) at node:internal/process/execution:449:12 at [eval]-wrapper:6:24 at runScriptInContext (node:internal/process/execution:447:60) at evalFunction (node:internal/process/execution:87:30) at evalScript (node:internal/process/execution:99:3) at node:internal/main/eval_string:74:3 Node.js v22.16.0 ``` --- > I'll fix the underlying issue in coming versions. @jehna So this is still a valid issue that should be fixed, and this issue should be re-opened to track that. Usage: https://github.com/jehna/humanify/blob/7beba2d32433e58bb77d0e1b0eda01c470fec3e2/src/progress.ts#L25-L31 Example of a potential fix: ```typescript export function showPercentage(percentage: number) { const percentageStr = Math.round(percentage * 100); const canUseCursorOps = process.stdout.isTTY && typeof process.stdout.clearLine === "function" && typeof process.stdout.cursorTo === "function"; if (!verbose.enabled && canUseCursorOps) { process.stdout.clearLine(0); process.stdout.cursorTo(0); process.stdout.write(`Processing: ${percentageStr}%`); } else { verbose.log(`Processing: ${percentageStr}%`); } if (percentage === 1 && canUseCursorOps) { process.stdout.write("\n"); } } ``` Ideally a similar more explicit fix would be added to `clearLine` in `showProgress` as well, instead of just relying on the optional chaining syntax. --- You can see that this would also be an issue with `process.stdout.clearLine`: ```shell ⇒ node -p -e "process.stdout.clearLine(0)" | cat [eval]:1 process.stdout.clearLine(0) ^ TypeError: process.stdout.clearLine is not a function at [eval]:1:16 at runScriptInThisContext (node:internal/vm:209:10) at node:internal/process/execution:449:12 at [eval]-wrapper:6:24 at runScriptInContext (node:internal/process/execution:447:60) at evalFunction (node:internal/process/execution:87:30) at evalScript (node:internal/process/execution:99:3) at node:internal/main/eval_string:74:3 Node.js v22.16.0 ``` Except that in the code, you're calling `process.stdout.clearLine` with the optional chaining syntax like this: https://github.com/jehna/humanify/blob/7beba2d32433e58bb77d0e1b0eda01c470fec3e2/src/progress.ts#L10 https://github.com/jehna/humanify/blob/7beba2d32433e58bb77d0e1b0eda01c470fec3e2/src/progress.ts#L28 Whereas for `process.stdout.cursorTo` you're not using the optional chaining syntax: https://github.com/jehna/humanify/blob/7beba2d32433e58bb77d0e1b0eda01c470fec3e2/src/progress.ts#L29 Looking at the git blame / history, the progress feature seemed to be first added in 70e31966e405c60790073d032042e2b39fe448ce on Aug 9, 2024, and neither used the optional chaining syntax: - https://github.com/jehna/humanify/commit/70e31966e405c60790073d032042e2b39fe448ce#diff-ae7dc0c4f05cb30c61f24ee7a16b994a4901803bdbcaf6c7dbedd40d6fd11386R24-R32 But then the optional chaining was added to `clearLine` in 05b6a8e261ebc6c9c4221e0ae1c34fe38c4531aa on Aug 9, 2024 as it broke the CI: - https://github.com/jehna/humanify/commit/05b6a8e261ebc6c9c4221e0ae1c34fe38c4531aa
Author
Owner

@0xdevalias commented on GitHub (Jul 27, 2025):

Since this issue is still valid, and I don't have the access to re-open it based on @ItsHarper 's findings/contribution; I created a new issue to track the ongoing bug, and how to fix it:

<!-- gh-comment-id:3123671665 --> @0xdevalias commented on GitHub (Jul 27, 2025): Since this issue is still valid, and I don't have the access to re-open it based on @ItsHarper 's findings/contribution; I created a new issue to track the ongoing bug, and how to fix it: - https://github.com/jehna/humanify/issues/546
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/humanify#30
No description provided.