使用 pm2 从其父文件夹启动 nuxt 时,出现错误“在 /home/.nuxt/dist/server 中找不到构建文件”

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

在我的

/home
文件夹中,我有 2 个 nuxt 应用程序,
callh
callr

ff373b7ddfdb:/home# ls
callh                ecosystem.config.js                  startup.sh           callr

我可以通过 cd 进入各自的文件夹并运行 npm start 来启动它们,但我想使用 pm2 来启动它们,所以在

ecosystem.config.js
中我写:
'./callh/node_modules/nuxt/bin/nuxt.js' ...
.

但是pm2报告

error FATAL  No build files found in /home/.nuxt/dist/server
。我如何让 nuxt 服务器知道代码位于
/home/callh/.nuxt/dist/server
而不是
/home/.nuxt/dist/server

2023-12-14 17:25:04:   Use either nuxt build or builder.build() or start nuxt in development mode.
2023-12-14 17:25:04:   at VueRenderer._ready (callh/node_modules/@nuxt/vue-renderer/dist/vue-renderer.js:550:13)
2023-12-14 17:25:04:   at async Server.ready (callh/node_modules/@nuxt/server/dist/server.js:451:5)
2023-12-14 17:25:04:   at async Nuxt._init (callh/node_modules/@nuxt/core/dist/core.js:344:7)
2023-12-14 17:25:04:
2023-12-14 17:25:04:
2023-12-14 17:25:04:  FATAL  No build files found in /home/.nuxt/dist/server.
2023-12-14 17:25:04: Use either `nuxt build` or `builder.build()` or start nuxt in development mode.

---更新---

我找到了一个解决方法,cd到每个子文件夹中运行pm2(相应地更改ecosystem.config.js),所以我的startup.sh更改为

#before it is just pm2 start ecosystem.config.js to start them all together.

cd /home/callh
pm2 start ecosystem.config.js --env production
cd /home/callr
pm2 start ecosystem.config.js --env production

ecosystem.config.js
更改为

module.exports = {
  apps: [
    {
      name: 'call history ',
      script: './node_modules/nuxt/bin/nuxt.js',
      args: 'start',
      watch: false,
      ...

感谢pm2,即使我运行了两次,也只有一个pm2进程。

但我觉得这可能是一个 nuxt bug,我会向他们提出。

nuxt.js pm2
1个回答
1
投票

找到解决方法后,我突然意识到在我的情况下使用 pm2 的正确方法是使用 cwd

 中的 
ecosystem.config.js
属性并将
ecosystem.config.js
放在父文件夹中。

  apps: [
    {
      name: 'callh',
      cwd: './callh', //set it or I will get "No build files found"
      script: './node_modules/nuxt/bin/nuxt.js',
      args: 'start',
      env:{
            NODE_ENV: "production"
            ...
      }
    },
    {
      name: 'callr',
      cwd: './callr',
      script: './node_modules/nuxt/bin/nuxt.js',
      args: 'start',
      env:{
            NODE_ENV: "production"
            ...
      }
    }
 ]

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