我相信您以某种方式在同一个文件夹中同时拥有 typescript 和 javascript。你能分享你的 tsconfig 文件吗?需要注意的重要一点是outdir,它将确保编译后的文件不会保存在同一个目的地。
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "dist", /* Redirect output structure to the directory. */
"strict": true, /* Enable all strict type-checking options. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
Package.json,这将允许您运行 npm 命令,例如 npm start....
{
"name": "learning_ts",
"version": "1.0.0",
"description": "",
"main": "dist/target_group.js",
"scripts": {
"debug": "tsc && node --nolazy dist/target_group.js",
"start": "tsc && node dist/target_group.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^14.11.1",
"aws-sdk": "^2.756.0",
"dotenv": "^8.2.0"
},
"devDependencies": {
"tslint": "^5.12.1",
"typescript": "^3.3.3"
}
}