Vue-storefront: Can't start in production mode ( pm2 in cluster mode )

Created on 21 Mar 2020  Â·  12Comments  Â·  Source: DivanteLtd/vue-storefront

Current behavior


When i try start server in production mode i got next errors in logs and server don't start
When start server using command
yarn start

1|server   | Error: Cannot find module '/app/start'
1|server   |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
1|server   |     at Function.Module._load (internal/modules/cjs/loader.js:864:27)
1|server   |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
1|server   |     at main (/app/node_modules/ts-node/src/bin.ts:226:14)
1|server   |     at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:485:3)
1|server   |     at Module._compile (internal/modules/cjs/loader.js:1158:30)
1|server   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
1|server   |     at Module.load (internal/modules/cjs/loader.js:1002:32)
1|server   |     at Function.Module._load (internal/modules/cjs/loader.js:901:14)
1|server   |     at /app/node_modules/pm2/lib/ProcessContainer.js:331:23

/root/.pm2/logs/server-error-0.log last 15 lines:
0|server   | Error: Cannot find module '/app/start'
0|server   |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
0|server   |     at Function.Module._load (internal/modules/cjs/loader.js:864:27)
0|server   |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
0|server   |     at main (/app/node_modules/ts-node/src/bin.ts:226:14)
0|server   |     at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:485:3)
0|server   |     at Module._compile (internal/modules/cjs/loader.js:1158:30)
0|server   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
0|server   |     at Module.load (internal/modules/cjs/loader.js:1002:32)
0|server   |     at Function.Module._load (internal/modules/cjs/loader.js:901:14)
0|server   |     at /app/node_modules/pm2/lib/ProcessContainer.js:331:23

/root/.pm2/logs/server-error-2.log last 15 lines:
2|server   | Error: Cannot find module '/app/start'
2|server   |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
2|server   |     at Function.Module._load (internal/modules/cjs/loader.js:864:27)
2|server   |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
2|server   |     at main (/app/node_modules/ts-node/src/bin.ts:226:14)
2|server   |     at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:485:3)
2|server   |     at Module._compile (internal/modules/cjs/loader.js:1158:30)
2|server   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
2|server   |     at Module.load (internal/modules/cjs/loader.js:1002:32)
2|server   |     at Function.Module._load (internal/modules/cjs/loader.js:901:14)
2|server   |     at /app/node_modules/pm2/lib/ProcessContainer.js:331:23

/root/.pm2/logs/server-error-3.log last 15 lines:
3|server   | Error: Cannot find module '/app/start'
3|server   |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
3|server   |     at Function.Module._load (internal/modules/cjs/loader.js:864:27)
3|server   |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
3|server   |     at main (/app/node_modules/ts-node/src/bin.ts:226:14)
3|server   |     at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:485:3)
3|server   |     at Module._compile (internal/modules/cjs/loader.js:1158:30)
3|server   |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
3|server   |     at Module.load (internal/modules/cjs/loader.js:1002:32)
3|server   |     at Function.Module._load (internal/modules/cjs/loader.js:901:14)
3|server   |     at /app/node_modules/pm2/lib/ProcessContainer.js:331:23

if i change 'exec_mode' from 'cluster' to 'fork' in 'ecosystem.json' server start without errors

Expected behavior

server should start without errors

Steps to reproduce the issue

  1. Build docker image from docker/vue-storefront/Dockerfile
  2. Start docker container without $VS_ENV=dev

Repository

Can you handle fixing this bug by yourself?

  • [ ] YES
  • [x] NO

Which Release Cycle state this refers to? Info for developer.

Pick one option.

  • [ ] This is a bug report for test version on https://test.storefrontcloud.io - In this case Developer should create branch from develop branch and create Pull Request 2. Feature / Improvement back to develop.
  • [ ] This is a bug report for current Release Candidate version on https://next.storefrontcloud.io - In this case Developer should create branch from release branch and create Pull Request 3. Stabilisation fix back to release.
  • [x] This is a bug report for current Stable version on https://demo.storefrontcloud.io and should be placed in next stable version hotfix - In this case Developer should create branch from hotfix or master branch and create Pull Request 4. Hotfix back to hotfix.

Environment details

  • Browser:
  • OS:
  • Node:
  • Code Version:

Additional information

I think for production mode better compile server script before run

Important VSF1 bug

Most helpful comment

Looks like problem was in wrong configuration ecosystem.json
i change script, args and remove node_args field

{
  "apps": [
    {
      "name": "server",
      "max_memory_restart": "1G",
      "instances": "4",
      "exec_mode": "cluster",
      "env": {
        "TS_NODE_PROJECT": "tsconfig-build.json",
        "NODE_ENV": "production"
      },
      "interpreter": "./node_modules/.bin/ts-node",
      "script": "./core/scripts/server.ts",
      "args": "-P tsconfig-build.json",
      "log_date_format": "YYYY-MM-DD HH:mm:ss",
      "ignore_watch": [
        "core/build/config.json",
        "node_modules"
      ]
    }
  ]
}

All 12 comments

@andrzejewsky can you please check it out?

Looks like problem was in wrong configuration ecosystem.json
i change script, args and remove node_args field

{
  "apps": [
    {
      "name": "server",
      "max_memory_restart": "1G",
      "instances": "4",
      "exec_mode": "cluster",
      "env": {
        "TS_NODE_PROJECT": "tsconfig-build.json",
        "NODE_ENV": "production"
      },
      "interpreter": "./node_modules/.bin/ts-node",
      "script": "./core/scripts/server.ts",
      "args": "-P tsconfig-build.json",
      "log_date_format": "YYYY-MM-DD HH:mm:ss",
      "ignore_watch": [
        "core/build/config.json",
        "node_modules"
      ]
    }
  ]
}

@OleksiiStepanov what pm2 version do you have?

@gibkigonzo is this still an issue?

@gibkigonzo is this still an issue?

Yes

@gibkigonzo i used pm2@^2.10.4:
version "2.10.4"
resolved "https://registry.yarnpkg.com/pm2/-/pm2-2.10.4.tgz#dd292fd26aed882f6e9f7b9652191387d2debe6a"

@gibkigonzo i used pm2@^2.10.4:
version "2.10.4"
resolved "https://registry.yarnpkg.com/pm2/-/pm2-2.10.4.tgz#dd292fd26aed882f6e9f7b9652191387d2debe6a"

That is already the default for the project.

I tried your solution: My pm2 clusters do boot, but it causes an infinite build and rebuild of the project on all 4 Pm2 server instances- Meaning that once it builds the service, it will somehow drop the service and starts the rebuilding process from the beginning again (repeat indefinitely) for each server. It doesn't allow me or any users to connect to the frontend service. Try reviewing the logs or try to connect to the frontend service using a private browser or incognito mode with a clean cache. You might find that you were viewing the cached/ offline version of the project.

@AntoniErdeg try to set NODE_ENV=production before start or ensure this variable already set. because build project should run only in development mode.

They have already tested the problem and can confirm it is still an issue. Before I need to repeat all steps including setting all file from dev to ‘production’ etc. Please read my very detail report found here: https://github.com/DivanteLtd/vue-storefront/issues/4454#issue-623797295 @OleksiiStepanov

@gibkigonzo @pkarw I have done some further testing on this issue. When testing my project on IOS and Linux - There is no problem with the booting or running of this service on those platforms. When the project was tested on the windows platform - It won't boot?? Using the exact same commands, the exact same project and package file. All systems are using yarn and have the exact same version of yarn installed - It just simply doesn't want to boot on windows without resulting in an error .

It is a very strange issues that I have spent the past week trying to resolve this issue and i have tested this issue on multiple machines. I guess not many users use windows servers or the windows platform when using your open source project.

This issues is related to this: #4454

@gibkigonzo @pkarw I have done some further testing on this issue. When testing my project on IOS and Linux - There is no problem with the booting or running of this service on those platforms. When the project was tested on the windows platform - It won't boot?? Using the exact same commands, the exact same project and package file. All systems are using yarn and have the exact same version of yarn installed - It just simply doesn't want to boot on windows without resulting in an error .

It is a very strange issues that I have spent the past week trying to resolve this issue and i have tested this issue on multiple machines. I guess not many users use windows servers or the windows platform when using your open source project.

This issues is related to this: #4454

Argh, I discovered the issue. As I prefer the Linux CMD interface: I use GitBash and even when you're an administrator, you will still need to launch gitBash as administrator and then boot the service.

any update about this issue ? am also having the same problem when running the VSF app in the production mode using yarn start. But for my case if I run locally it works but if I run on my kubernetes pods I always get the "Error: Cannot find module '/app/start'" error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulocoghi picture paulocoghi  Â·  5Comments

pkarw picture pkarw  Â·  5Comments

jonashrem picture jonashrem  Â·  3Comments

cartooncatfish picture cartooncatfish  Â·  3Comments

vishal-7037 picture vishal-7037  Â·  5Comments