我正在尝试使用 pm2 在 AWS EC2 上编译打字稿应用程序(节点和快速服务器)。服务器使用 npm 构建得很好,但是当我运行 pm2 start src/app.ts 时,它因错误而中断:
TSError: ⨯ Unable to compile TypeScript:0|app | src/app.ts(5,13): error TS2349: This expression is not callable. 0|app | Type 'typeof e' has no call signatures. 0|app | at createTSError (/usr/lib/node_modules/pm2/node_modules/ts-node/src/index.ts:859:12) 0|app | at reportTSError (/usr/lib/node_modules/pm2/node_modules/ts-node/src/index.ts:863:19) 0|app | at getOutput (/usr/lib/node_modules/pm2/node_modules/ts-node/src/index.ts:1077:36) 0|app | at Object.compile (/usr/lib/node_modules/pm2/node_modules/ts-node/src/index.ts:1433:41) 0|app | at Module.m._compile (/usr/lib/node_modules/pm2/node_modules/ts-node/src/index.ts:1617:30) 0|app | at Module._extensions..js (node:internal/modules/cjs/loader:1245:10) 0|app | at Object.require.extensions.<computed> [as .ts] (/usr/lib/node_modules/pm2/node_modules/ts-node/src/index.ts:1621:12) 0|app | at Module.load (node:internal/modules/cjs/loader:1069:32) 0|app | at Function.Module._load (node:internal/modules/cjs/loader:904:12) 0|app | at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
我的 tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
我也认为错误出在我的 app.ts 文件中,因为“src/app.ts(5,13):”这一行,所以我也将其附在下面:
import * as express from "express";
import loaders from "./loaders";
import config from "./config";
const app = express();
loaders({ expressApp: app });
const server = app.listen(config.port, () =>
console.log(`
🚀 Server ready at: http://localhost:${config.port}${config.api.prefix}
`)
);