简体   繁体   English

Typescript 使用 tsc-watch 编译 - 文件 dist/server.js 具有不受支持的扩展名

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

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'" . 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: tsconfig.json文件如下所示:

"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.尝试将allowJs更改为true但这也不起作用。 Also, this setting works in an online workspace where I am learning to write an API using Express and Typescript.此外,此设置适用于在线工作区,我正在学习使用 Express 和 Typescript 编写 API。 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.当我尝试在本地系统上运行相同的程序时会出现这些问题。本地系统和在线工作区上的节点版本是 10.18.0。

The error was due to the use of single quotes in the npm script "watch": "tsc-watch --onSuccess 'node./dist/server.js' ", .该错误是由于在 npm 脚本"watch": "tsc-watch --onSuccess 'node./dist/server.js' ",中使用了单引号引起的。

Solved the issue by escaping double quotes.通过 escaping 双引号解决了这个问题。 Don't know if its an OS thing.不知道是不是操作系统的问题。 Am using VSCode editor on Windows 10.我在 Windows 10 上使用 VSCode 编辑器。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 tsc-watch 抛出错误:“文件 'dist/index.js' 是 JavaScript 文件。 您的意思是启用“allowJs”选项吗?” - tsc-watch throwing error: “File 'dist/index.js' is a JavaScript file. Did you mean to enable 'allowJs' option?” VSCode TypeScript problemMatcher `$tsc-watch` 不看 - VSCode TypeScript problemMatcher `$tsc-watch` not watching tsc-watch 消耗 TSC_NONPOLLING_WATCHER 吗? - Does tsc-watch consume TSC_NONPOLLING_WATCHER? tsc 编译使用文件扩展名导入的 typescript - tsc compile typescript which imports using file extension 将tsc的节点版本与Visual Studio 2015 TypeScript扩展一起使用 - Using the Node version of tsc with Visual Studio 2015 TypeScript Extension 引入打字稿后,带有express server.js的CRA中断 - CRA with express server.js breaks after introducing typescript 在 tsc TypeScript 编译中包含 CSS 文件 - Include CSS files in tsc TypeScript compilation 是否可以使用tsc命令将单个TypeScript文件编译到输出路径? - Is it possible to compile a single TypeScript file to an output path using the tsc command? typescript - tsc 如何将其他文件类型复制到 dist 文件夹 - typescript - tsc how to copy other files type to the dist folder 在 TypeScript 中使用 SweetAlert2,找不到模块“sweetalert2/dist/sweetalert2.js”的声明文件 - Using SweetAlert2 with TypeScript, could not find a declaration file for module 'sweetalert2/dist/sweetalert2.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM