Skip to content

child_process spawn can't get tsc CLI stdoutΒ #62491

@kimown

Description

@kimown

πŸ”Ž Search Terms

"cli", "tsc"

πŸ•— Version & Regression Information

  • This changed between versions 5.9.2

⏯ Playground Link

No response

πŸ’» Code

I want to use child_process get tsc CLI output for further analyse.

npm i typescript -g
tsc --version
Version 5.9.2

cd /tmp
mkdir a
cd a
tsc --init

cat <<\EOT>  index.ts 
const a:number = ""
console.info(a)
EOT

tsc --noEmit
index.ts:1:7 - error TS2322: Type 'string' is not assignable to type 'number'.

1 const a:number = ""
        ~


Found 1 error in index.ts:1



// use child_process spawn get tsc CLI output

cat <<\EOT>  get_output.mjs
import child_process from 'child_process';
const { spawn } = child_process;

async function test() {
  const ls = spawn('tsc', ['--noEmit'], {});

  ls.stdout.on('data', (data) => {
    console.log(`stdout: ${data}`);
  });

  ls.stderr.on('data', (data) => {
    console.error(`stderr: ${data}`);
  });

  ls.on('close', (code) => {
    console.log(`child process exited with code ${code}`);
  });
}
test();
EOT

node get_output.mjs 
stdout: index.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.

child process exited with code 2


πŸ™ Actual behavior

stdout missing information below

1 const a:number = ""
        ~


Found 1 error in index.ts:1

πŸ™‚ Expected behavior

stdout should same as tsc CLI output

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions