PM2 如何在生产模式下启动nextjs项目?

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

我想在 pm2 中运行一个项目。

我的文件夹结构:

screen with my folder structure

我的package.json:

"scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start -p 7777",
    "type-check": "tsc",
    "gensitemap": "node generate-sitemap.mjs",
    "prod": "yarn && npm run build && npm run start"
  },

我的ecosystem.config.js

module.exports = {
  apps: [
    {
      name: 'core',
      script: 'yarn --cwd core prod',
      watch: false,
    },
  ],
};

什么时候,我开始

pm2 start ecosystem.config.js

我在日志中收到以下错误
error - Invalid project directory provided, no such directory: D:\React\MyProject\src\core\prod

我尝试了不同的方法在生产模式下运行。 它仅在开发模式下运行

next.js web-deployment pm2
1个回答
0
投票

如果您使用nextjs,请尝试使用下面的代码。 脚本已更改

module.exports = {
  apps: [
    {
      name: 'core',
      script: "node_modules/next/dist/bin/next",
      watch: false,
    },
  ],
};
© www.soinside.com 2019 - 2024. All rights reserved.