You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从/home目录用pm2启动多Nuxt应用时构建文件路径错误的解决方法

问题:从父目录用PM2启动多Nuxt应用时找不到构建文件

当从父目录/home使用pm2启动Nuxt应用时,出现错误:No build files found in /home/.nuxt/dist/server。

我的/home目录下有两个Nuxt应用:callh和callr,目录结构如下:

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

单独进入每个应用目录执行npm start可以正常启动,但想通过pm2同时启动两者,于是在ecosystem.config.js中配置了'./callh/node_modules/nuxt/bin/nuxt.js',结果pm2报错找不到构建文件——实际构建文件在/home/callh/.nuxt/dist/server,但Nuxt却去/home/.nuxt/dist/server查找,如何让Nuxt识别正确的构建文件路径?

报错日志

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.

临时解决方法

找到一个可行的临时方案:进入每个应用子目录单独启动pm2,同步修改ecosystem.config.js配置。

修改后的startup.sh脚本

# 之前是直接执行pm2 start ecosystem.config.js同时启动所有应用
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的特性,重复执行该脚本不会生成重复进程。


内容的提问来源于stack exchange,提问作者Qiulang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 00:00:54