Question

  • Creator
    Topic
  • #3937958

    Specifying a file for error messages within TypeScript tsconfig.json

    by wally96334 ·

    I am running the TypeScript transpiler on some code. I want to trap any error messages that the transpiler might emit to a file specified within my tsconfig.json. I do not see an attribute within the specifications for doing that.

    Am I missing something?

    Thanks!

You are posting a reply to: Specifying a file for error messages within TypeScript tsconfig.json

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Answers

  • Author
    Replies
    • #3939318
      Avatar photo

      Where do you see the error messages now?

      by rproffitt ·

      In reply to Specifying a file for error messages within TypeScript tsconfig.json

      I see there is a Command Line Interface (CLI) at https://www.typescriptlang.org/docs/handbook/compiler-options.html so I’d try the command line and see if the errors show on screen.

      After that we can use the old redirects from the CLI.

      https://helpdeskgeek.com/how-to/redirect-output-from-command-line-to-text-file/ is a refresher for both standard and error output.

      • #3939316

        They are displayed in the command window … depending …

        by wally96334 ·

        In reply to Where do you see the error messages now?

        Hi RProffitt,

        THANKS for the response.

        I know about the command line option with redirection.

        I was hoping that I wouldn’t have to go into the details of my problem,
        that there would be a simple config option that I could set that I am not aware of.

        Here is my code, with comments as to what I tried, and what happened.

        ————————————————————————-

        static class TypeScriptCompiler
        {
        static string L_file_path;
        static string L_TS_file_spec;
        static string L_bat_TS_file_spec;
        static string L_JS_file_spec;
        static string L_tsc_file_spec;

        public static void Compile(string P_tsPath, CLS_Options P_options = null)
        {
        L_file_path = @”C:\a01_temp”;
        L_TS_file_spec = Path.Combine (L_file_path, “test.ts”);
        L_JS_file_spec = Path.Combine (L_file_path, “test.js”);
        L_tsc_file_spec
        = “C:\\Users\\Ron Smith\\AppData\\Roaming\\npm\\node_modules\\typescript\\bin\\tsc”;

        string L_cmd;

        Process L_tsc_process = new Process();
        ProcessStartInfo psi;

        // THIS ProcessStartInfo set threw the Win32Exception listed below.

        //psi = new ProcessStartInfo
        // (“tsc”,
        // ” –project C:\\a01_temp\\tsconfig.json”);

        // System.ComponentModel.Win32Exception
        // HResult=0x80004005
        // Message=The system cannot find the file specified
        // Source=System
        // StackTrace:
        // at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
        // at NS_TypeScript.TypeScriptCompiler.Compile(String P_tsPath, CLS_Options P_options)
        // in K:\Software Development\CLS_TypeScript_01.cs:line 235
        // at NS_TypeScript.Program.Main(String[] args)
        // in K:\Software Development\CLS_TypeScript_01.cs:line 48

        // I do not know why the process could not find “tsc” like it should have.
        // If anyone could figure this out, it might solve my problem.

        CONT’D …

        • #3939315

          PART 2

          by wally96334 ·

          In reply to They are displayed in the command window … depending …

          // NEXT APPROACH: Try writing the command to a batch file,
          // then execute the batch file.

          // The batch file DID execute properly,
          // and the errors were displayed in the command box,
          // but the output was not redirected when this was run from a separate process
          // within .NET (C#).

          // The error messages were indeed redirected to the given log file (cmpl_diag.txt)
          // when the generated batch file was run directly from the command line.

          // THIS is stuff that was tried before but did not work,
          // including a pipe to another process that might handle the redirect.
          //L_cmd = L_tsc_file_spec + $” –project C:/a01_temp/tsconfig.json”;
          //L_cmd = “cmd tsc” + $” –project C:/a01_temp/tsconfig.json”;
          //L_cmd = “tsc” + $” –project C:/a01_temp/tsconfig.json cmpl_diag.txt 2>&1″;
          //L_cmd = “tsc” + $” –project C:/a01_temp/tsconfig.json | more >cmpl_diag_02.txt”;
          //L_cmd = “tsc” + ” –project C:\\a01_temp\\tsconfig.json | more >cmpl_diag_02.txt”;
          //L_cmd = “tsc” + ” –project C:\\a01_temp\\tsconfig.json > cmpl_diag_02.txt 2>&1″;

          // THIS is the most-recent attempt.

          L_cmd = “tsc” + $” –project C:/a01_temp/tsconfig.json > cmpl_diag_02.txt 2>&1″;

          // Creating the batch file.
          L_bat_TS_file_spec = Path.Combine (L_file_path, “test.bat”);
          using (StreamWriter
          L_SW = new StreamWriter (L_bat_TS_file_spec))
          {
          L_SW.Write (L_cmd);
          }
          psi = new ProcessStartInfo (L_bat_TS_file_spec);

          // run without showing console windows
          psi.CreateNoWindow = true;
          psi.UseShellExecute = false;
          psi.Verb = “runas”;

          // redirects the compiler error output, so we can read
          // and display errors if any
          psi.RedirectStandardOutput = true;
          psi.RedirectStandardError = true;

          L_tsc_process.StartInfo = psi;
          L_tsc_process.Start();

          // SHOULD read the error output
          // … but nothing was read.
          var msg = L_tsc_process.StandardError.ReadToEnd();

          // make sure it finished executing before proceeding
          L_tsc_process.WaitForExit();

          CONT’D …

        • #3939314

          PART 3

          by wally96334 ·

          In reply to PART 2

          // TRIED moving this down below the “WaitForExit”
          // … but still nothing was read.
          //var msg = L_tsc_process.StandardError.ReadToEnd();
          }
          }

          ———————————————————–

          C:\\a01_temp\\tsconfig.json

          {
          “compilerOptions”: {
          “sourceMap”: true,
          “noImplicitAny”: true,
          “module”: “commonjs”,
          “target”: “es5”,
          “allowJs”: true,
          “removeComments”: false,
          “typeRoots”: [
          “C:\\TypeScript\\a16_bin\\node_modules\\@types”
          ]
          },
          “include”: [
          “C:\\a01_temp\\test.ts”
          ]
          }

          THANKS AGAIN!

        • #3939305

          PROBLEM SOLVED!

          by wally96334 ·

          In reply to PART 3

          PROBLEM SOLVED!

          Specifying the absolute file path on the output file using the generated batch file approach solved the problem.

          THANKS for reading.

Viewing 0 reply threads