Typescript compilation using tsc-watch - File dist/server.js has unsupported extension

Viewed 1473

I am trying to compile my typescript server side file (using tsc-watch) to an output directory dist by running the npm script "watch": "tsc-watch --esModuleInterop ./src/server.ts --outDir ./dist --onSuccess 'node ./dist/server.js'". However, I keep running into the following error:

error TS6054: File 'dist/server.js'' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.

The tsconfig.json file looks like this:

"compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Basic Options */
   
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "es2020",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    // "allowJs": true, 

    /* Strict Type-Checking Options */
    

    /* Additional Checks */
    

    /* Module Resolution Options */
    
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

    /* Source Map Options */
   
    /* Experimental Options */

    /* Advanced Options */
    "skipLibCheck": true,                     /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */
  }
}

Tried changing allowJs to true but that does not work either. Also, this setting works in an online workspace where I am learning to write an API using Express and Typescript. These issues arise when I try to run the same on my local system .Node version on local system and online workspace is 10.18.0 .

1 Answers

The error was due to the use of single quotes in the npm script "watch": "tsc-watch --onSuccess 'node ./dist/server.js' ", .

Solved the issue by escaping double quotes. Don't know if its an OS thing. Am using VSCode IDE on Windows 10.

"watch": "tsc-watch --onSuccess \"node ./dist/server.js\"",

Related