[英]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.