2

When trying to run npm start, I get the error:

Error: EACCES: permission denied, open '/root/.pm2/module_conf.json'
    at Object.openSync (node:fs:582:3)
    at Object.readFileSync (node:fs:450:35)
    at Object.Configuration.getAllSync (/usr/local/lib/node_modules/pm2/lib/Configuration.js:299:26)
    at Object.Configuration.getSync (/usr/local/lib/node_modules/pm2/lib/Configuration.js:270:30)
    at new API (/usr/local/lib/node_modules/pm2/lib/API.js:117:44)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/binaries/CLI.js:22:11)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
/usr/local/lib/node_modules/pm2/node_modules/@pm2/agent/src/InteractorClient.js:58
          if (stats.uid === 0) {
                    ^

TypeError: Cannot read property 'uid' of undefined
    at /usr/local/lib/node_modules/pm2/node_modules/@pm2/agent/src/InteractorClient.js:58:21
    at FSReqCallback.oncomplete (node:fs:195:21)

the command in package.json looks like this

{
    "scripts": {
        "start": "pm2 start ./node_modules/laravel-echo-server/dist/index.js"
    },
    "dependencies": {
        "laravel-echo-server": "^1.6.2",
        "save": "^2.4.0"
    }
}

But if I run the command in the terminal pm2 start ./node_modules/laravel-echo-server/dist/index.js it works fine

/app # pm2 start ./node_modules/laravel-echo-server/dist/index.js
[PM2] Starting /app/node_modules/laravel-echo-server/dist/index.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name           │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1   │ index          │ default     │ 1.6.2   │ fork    │ 13626    │ 0s     │ 0    │ online    │ 0%       │ 7.6mb    │ root     │ disabled │
│ 0   │ laravelEcho    │ default     │ 1.6.2   │ fork    │ 13608    │ 1s     │ 1207 │ online    │ 0%       │ 69.6mb   │ root     │ disabled │
└─────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. Type 'pm2 save' to synchronize.

After searching the internet for a solution to the problem, I saw a possible solution, but it didn't work for me either. This solution was to create an ecosystem.config.js file here is an example with this solution but it doesn't work either

package.json

{
    "scripts": {
        "start": "pm2 start ecosystem.config.js"
    },
    "dependencies": {
        "laravel-echo-server": "^1.6.2",
        "save": "^2.4.0"
    }
}

ecosystem.config.js

module.exports = {
    apps : [
        {
            name: "laravelEcho",
            script: "./node_modules/laravel-echo-server/dist/index.js",
            args : "start"
        }
    ]
}

Perhaps this will help when looking for the problem, I am using Docker Dockerfile

FROM node:alpine

WORKDIR /app

RUN npm install pm2:2.9.2 -g && pm2 update

EXPOSE 8888

What could be the problem?

2 Answers2

0

not sure it's great to run it as root, have a look here on pm2s git repo on user access: Starting PM2 as a non-root user is broken

Lune
  • 43
  • 6
-1

i think you can fix the "permission denied" with running this as su so just run sudo npm start but because i can't code in js i can't help you with the errors i'm sorry!:/ I hope i could help you anyways a little bit!!

Namechange
  • 31
  • 6
  • by the way are you on linux or mac? Because if you're on windows you have to run it as administrator – Namechange Jul 01 '21 at 13:06
  • i used linux Ubuntu and docker about sudo, by default docker container runs as root user and unfortunately i can't use sudo command in docker – Vladyslav Chalyi Jul 01 '21 at 13:10
  • https://stackoverflow.com/questions/50639690/on-npm-install-unhandled-rejection-error-eacces-permission-denied Look here i think that can help you, there's something about `chown` – Namechange Jul 01 '21 at 13:13
  • I tried ``` /app # chown -R $(whoami) ~/.pm2 ``` and after ``` cd ~/.pm2 chown -R $(whoami) module_conf.json but it doesn't work either – Vladyslav Chalyi Jul 01 '21 at 13:25