使用 pm2 start 启动应用程序时,在意外标记“../lib/cli.js”附近出现语法错误

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

我在使用

pm2 start
 执行 
ecosystem.config.js

时遇到问题
/root/.nvm/versions/node/v18.16.0/bin/npm: line 2: require('../lib/cli.js')(process)'
/root/.nvm/versions/node/v18.16.0/bin/npm: line 2: syntax error near unexpected token '../lib/cli.js''

我在我的机器上完全重新安装了节点,但仍然遇到这个问题。

nvm -v 0.39.3 节点-v 18.16.0 npm -v 9.5.1 pm2-v 5.3.0

module.exports = {
  apps: [
    {
      name: "strapi_portfolio",
      cwd: "./server",
      script: "npm",
      args: "run start-prod",
      autorestart: true,
    },
    {
      name: "nextjs_portfolio",
      cwd: "./client",
      script: "npm",
      args: "run start-prod",
      autorestart: true,
      wait_ready: true,
      listen_timeout: 60000,
    },
  ],
};

我的

start-prod
脚本:

"start-prod" : "npm install && npm run build && npm run start"

我没有得到的是,我的流程在单独手动启动时可以工作......

看起来他们正在工作,但在某些时候遇到了未知问题 image

PM2报告

--- PM2 report ----------------------------------------------------------------
Date                 : Wed Jun 14 2023 00:52:29 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.3.0
node version         : 18.16.0
node path            : /root/.local/share/pnpm/pm2
argv                 : /root/.nvm/versions/node/v18.16.0/bin/node,/root/.local/share/pnpm/global/5/.pnpm/[email protected]/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
uptime               : 14min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.3.0
node version         : 18.16.0
node path            : /root/.local/share/pnpm/pm2
argv                 : /root/.nvm/versions/node/v18.16.0/bin/node,/root/.local/share/pnpm/global/5/node_modules/pm2/bin/pm2,report
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : AMD EPYC 7282 16-Core Processor
cpus nb              : 4
freemem              : 7807197184
totalmem             : 8346025984
home                 : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬─────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name                │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼─────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1  │ nextjs_portfolio    │ default     │ 0.39.3  │ fork    │ 0        │ 0      │ 30   │ errored   │ 0%       │ 0b       │ root     │ disabled │
│ 0  │ strapi_portfolio    │ default     │ 0.39.3  │ fork    │ 0        │ 0      │ 30   │ errored   │ 0%       │ 0b       │ root     │ disabled │
└────┴─────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2        | 2023-06-14T00:42:03: PM2 log: Script /root/.nvm/versions/node/v18.16.0/bin/npm had too many unstable restarts (16). Stopped. "errored"
PM2        | 2023-06-14T00:42:03: PM2 log: App [nextjs_portfolio:1] starting in -fork mode-
PM2        | 2023-06-14T00:42:03: PM2 log: App [nextjs_portfolio:1] exited with code [2] via signal [SIGINT]
PM2        | 2023-06-14T00:42:03: PM2 log: Script /root/.nvm/versions/node/v18.16.0/bin/npm had too many unstable restarts (16). Stopped. "errored"
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online
PM2        | 2023-06-14T00:43:03: PM2 log: App [nextjs_portfolio:1] online

javascript node.js linux npm pm2
1个回答
0
投票

原来我只是使用了错误的节点版本...

我使用节点

v16.16.0
编写了我的项目,但尝试使用节点
v18.16.0

启动它们

我使用 nvm 下载了

v16.16.0
,然后在我的
ecosystem.config.js

中添加了这一行
interpreter: "[email protected]"

所以看起来是这样的:

module.exports = {
  apps: [
    {
      name: "strapi_portfolio",
      interpreter: "[email protected]", // HERE
      cwd: "./server",
      script: "npm",
      args: "run start-prod",
      autorestart: true,
    },
    {
      name: "nextjs_portfolio",
      interpreter: "[email protected]", // HERE
      cwd: "./client",
      script: "npm",
      args: "run start-prod",
      autorestart: true,
      wait_ready: true,
      listen_timeout: 60000,
    },
  ],
};
© www.soinside.com 2019 - 2024. All rights reserved.