typescripttsserver

How to access TS Server log?


I cannot get the TS Server logging to work for my build script. I need it as I want to learn how to make a plugin for TypeScript.

The VS Code logs won't do, so no use pointing me to the Open TS Server log command.

If I understand correctly, I need to set the TTS_LOG environment variable before running tsc. https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin#setting-up-typescript-server-logging

So here is what I tried:

  1. I modified my build script in package.json, but no log file appeared after using it with npm run build. My code compiled correctly though.
{
  "script": {
    "build": "cross-env TSS_LOG=\"-logToFile true -file D:\\ts-server.log -level verbose\" tsc"
  }
}
  1. Same with typing the following command in PowerShell, in Git Bash and in Command Prompt:
npx cross-env TSS_LOG="-logToFile true -file D:\ts-server.log -level verbose" tsc
  1. Same with trying to set the variable directly in PowerShell before running tsc
> $Env:TSS_LOG="-logToFile true -file D:\ts-server.log -level verbose"
> npx tsc
  1. Same with trying to set the variable directly in Git Bash before running tsc
$ TSS_LOG="-logToFile true -file D:\ts-server.log -level verbose"
$ npx tsc
  1. Same with trying to set the variable directly in Command Prompt before running tsc
> SET TSS_LOG="-logToFile true -file D:\ts-server.log -level verbose"
> npx tsc
  1. Same when using a slash instead of a backslash in the log file path for all of the above methods: D:/ts-server.log

What am I doing wrong?

Here is my setup:

Update: I just tried on Ubuntu 20.04.5 LTS with Node 20.11.1 and I cannot get a log either, so now I'm sure it is not OS related.


Solution

  • I dived into TypeScript's code and fount out tsc doesn't use TS Server to begin with. Then, looking back at the tutorial I linked in the question, I realized its about plugins meant to be tested and used on VS Code (maybe on other IDEs too).

    So, to answer my question:

    1. It's not possible to get a TS Server log using tsc
    2. To set TSS_LOG properly on Windows 11, you have to go through Settings > System > Advanced system settings > Environment Variables...