pm2 无法启动 typescript ESM

问题描述 投票:0回答:0

我想在 pm2 中启动 typescript ESM

我配置ESM模块:

  1. 添加“类型”:“模块”到 package.json
  2. 添加“模块”:“Node16”到 tsconfig.json
  3. add "esm": true 到 tsconfig.json 的 ts-node 部分

我尝试使用 pm2 启动一个简单的程序 main.ts:

import { msg } from './lib/helper.js';

msg('Hello world!');

并收到此错误:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /var/node/srv2/src/main.ts

标准命令工作正常:

 ts-node src/main.ts

我尝试使用 ecosystem.config.cjs - 但它也不起作用。

我把完整的例子放到github上: https://github.com/gayratv/pm2-typesript-esm

有什么方法可以使用 pm2 启动 typescript ESM 吗?

pm2
© www.soinside.com 2019 - 2024. All rights reserved.