Search code examples
reactjssingle-page-applicationpm2serve

PM2 serve SPA build folder. It works but has tons of errors like "Error while serving ... ENOENT: no such file or directory..."


The problem is that the logs are flooded, but it works fine.

The build folder contains the build from React using CRA (Create React App).
So from the PM2 Docs I have this:

ecosystem.config.js

module.exports = {
    name: "projectName",
    script: "serve",
    watch: true,
    env: {
        NODE_ENV: "production",
        PM2_SERVE_PATH: './build',
        PM2_SERVE_PORT: 5001,
        PM2_SERVE_SPA: 'true',
        PM2_SERVE_HOMEPAGE: './index.html'
    },
}

I'm using PM2 serve command.

Command to start PM2 process:
pm2 start

Errors
Only happens when I enter for the first time or when I reload.
Error while serving /.../projectName/build/routeX with content-type text/plain : ENOENT: no such file or directory, open '/.../projectName/build/routeX'


Solution

  • This issue is fixed in pm2 v5.2.0

    https://github.com/Unitech/pm2/pull/5272