typescript - 如何使用 ts-node 解决集群模式下的 pm2 错误
问题描述
我正在尝试将 pm2 与 ts-node 一起使用进行部署。
当我使用cluster-mode
时,出现 pm2 实例错误,即找不到模块...
错误:找不到模块“{path}/start”
在 main ({path}/node_modules/ts-node/dist/bin.js:178:20)
在对象。({path}/node_modules/ts-node/dist/bin.js:404:5)
这是我的生态系统.config.js,"production": "pm2-runtime start ecosystem.config.js --env production"
这是我的包脚本。
module.exports = {
apps: [
{
script: "ts-node",
args: "./server.ts",
instances: "max",
exec_mode: 'cluster_mode',
node_args: '-r esm'
env_production: {...}
}
]
}
当我使用fork-mode
notcluster-mode
时,该应用程序运行良好。我不知道如何解决这个问题。请告诉我任何想法。
解决方案
据我了解,使用 JS 以外的任何解释器都需要 fork 模式,因此禁止直接执行 oy typescript。您需要将 /server.ts 编译为 /server.js 以启用集群模式。
https://pm2.keymetrics.io/docs/tutorials/using-transpilers-with-pm2#execution-interpreter
将转译器与 PM2 一起使用的最简单方法是覆盖执行解释器 (exec_interpreter)。请注意,如果更改此设置,您的代码将仅在 fork_mode 下工作。
推荐阅读
- vue.js - VueJs - 使用 Slot 名称调用另一个组件中的组件
- android - 如何使用 kotlin 删除 view-pager 2 中的项目?
- python - 使用 Figure() 对象更新 FigureCanvasQTAgg 画布
- nginx - Nginx try_files 与别名一起工作
- php - 在 PHP 中用点转换时间戳(“yyyy.mm.dd hh:nn:ss.zzz”)
- python - git pull on running 代码会导致损坏
- google-cloud-platform - 当自动缩放策略设置为目标 HTTP 负载平衡利用率时,MIG 如何自动缩放?
- python - Flask-Admin:按不同字段对列进行排序
- java - PostgresSQL jsonb 列 - “。”的问题
- sql-server - SSDT/Visual Studio 数据库项目发布 DACPAC 引用 DML 表触发器 SQL71501