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

TypeError: process.stdout.cursorTo is not a function #10012

Closed
hyunbinseo opened this issue May 23, 2023 · 2 comments
Closed

TypeError: process.stdout.cursorTo is not a function #10012

hyunbinseo opened this issue May 23, 2023 · 2 comments

Comments

@hyunbinseo
Copy link
Contributor

Describe the bug

After upgrading to SvelteKit 1.17.0+ endpoint prerender with process.stdout.cursorTo() fails.

Seems to be related to #9919 - prerender in worker rather than subprocess to support Deno.

Reproduction

// src/routes/+server.ts

import type { RequestHandler } from './$types';

export const prerender = true;

export const GET = (() => {
  const now = new Date().toISOString();
  process.stdout.write(now);
  process.stdout.cursorTo(0);
  return new Response(now);
}) satisfies RequestHandler;
npm i @sveltejs/kit@1.17.0
npm run build
✓ built in 217ms

TypeError: process.stdout.cursorTo is not a function

node:internal/event_target:1012
 process.nextTick(() => { throw err; });
                          ^
Error: 500 /

Logs

No response

System Info

System:
  OS: macOS 13.3.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 158.95 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
  npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
Browsers:
  Chrome: 113.0.5672.126
  Firefox: 113.0.1
  Safari: 16.4
npmPackages:
  @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
  @sveltejs/kit: ^1.17.0 => 1.17.0 
  svelte: ^3.54.0 => 3.59.1 
  vite: ^4.3.0 => 4.3.8

Severity

blocking an upgrade

Additional Information

No response

@gtm-nayan
Copy link
Contributor

Related nodejs/node#28386

@hyunbinseo
Copy link
Contributor Author

Solution

Check if a stream is connected to a TTY context.

const { isTTY } = process.stdout;
if (isTTY) process.stdout.write('-'.repeat(100));

Reference

process.stdout.fd

This property refers to the value of underlying file descriptor of process.stdout. The value is fixed at 1. In Worker threads, this field does not exist.


A note on process I/O

$ node -p "Boolean(process.stdin.isTTY)"
# true

$ echo "foo" | node -p "Boolean(process.stdin.isTTY)"
# false

$ node -p "Boolean(process.stdout.isTTY)"
# true

$ node -p "Boolean(process.stdout.isTTY)" | cat
# false 

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

2 participants