'Why is my React App not serving with PM2?

I am trying to run my React App with PM2 on an Ubuntu server. It has been running fine for years before today, and suddenly it stopped.

The one change I made today was that I reset my root password. But I can't think why that would make a difference.

I have created the app build.

If I just serve the app from the root directory of the application with serve -s build it serves correctly.

Then I try to serve the file using PM2 with a file 'ecosystem.config.js' that in my server root directory. This is the module:

  apps : [{
        name:'myapp',
        script: '../../var/www/myapp',
        interpreter : 'none',
        args: 'sudo serve -s build',
        watch: true,
        env: {
                NODE_ENV:'development',
        },
        env_production : {
                NODE_ENV: 'production'
        }
   }]
}

I run pm2 restart all and it seems to restart, but then it errors.

The log shows the following:

at WriteStream.emit (events.js:210:5)
at internal/fs/streams.js:299:10
at FSReqCallback.oncomplete (fs.js:146:23)
Error: Cannot find module '/var/www/myapp'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js:297:23
at wrapper (/usr/local/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
at next (/usr/local/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
at /usr/local/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
at WriteStream.<anonymous> (/usr/local/lib/node_modules/pm2/lib/Utility.js:186:13)
at WriteStream.emit (events.js:210:5)
at internal/fs/streams.js:299:10
at FSReqCallback.oncomplete (fs.js:146:23)```

Thank you for any ideas.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source