【问题标题】:Pm2 is unable to find start scriptpm2 找不到启动脚本
【发布时间】:2022-07-18 12:51:37
【问题描述】:

我目前遇到的问题是我尝试使用 pm2 启动我的 next.js 应用程序,但它一直失败。

我运行以下命令...

npm run build

pm2 start npm --name "next" -- start

在nextjs项目的根目录下(有/node_modules/pages等的那个)

但是,当我运行命令时,我收到以下错误

[PM2][ERROR] Script not found: C:\Users\...\frontend\start

我看到人们谈论使用ecosystem.config.js 文件来指定脚本的目录。但是,我似乎找不到next start 脚本的目录。

任何帮助将不胜感激。

我看到的每一个地方都告诉我运行上面运行的 pm2 命令,任何解决找不到脚本问题的方法都建议使用 ecosystem.config.js 文件。但是,我无法找到 next start 脚本的正确路径。

【问题讨论】:

  • 我在 Windows Server 2019 上运行它
  • 你解决过这个问题吗? linux机器上同样的问题...
  • 不幸的是没有,我似乎找不到任何地方甚至试图解决问题。

标签: next.js pm2


【解决方案1】:

聚会迟到了,但我的 NextJs + PM2 + Windows 在多次尝试后有点工作。

我的文件夹结构:

PM2App
======
-apps (where NextJS and other apps reside)
 -nextapp
  -node_modules
  -package.json
  ...
 -otherapp
 ...
-ecosystem.config.js

ecosystem.config.js 是这样的:

module.exports = {
    apps : [{
      name: 'NextJS Apps',
      script: 'node_modules/next/dist/bin/next',
      args: 'start -p 3000', //running on port 3000
      cwd: "./apps/nextapp",
      instances: 1,
      watch: false,
      env: {
          ...
      },
    }]
  };

使用以下命令启动 pm2:

pm2 start ecosystem.config.js
@
pm2 start

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2016-01-31
    • 1970-01-01
    • 2023-01-12
    相关资源
    最近更新 更多