Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt SSR deployment on docker with pm2 has error. #8704

Closed
farshidrezaei opened this issue Jan 27, 2021 · 29 comments
Closed

Nuxt SSR deployment on docker with pm2 has error. #8704

farshidrezaei opened this issue Jan 27, 2021 · 29 comments

Comments

@farshidrezaei
Copy link

Versions

  • nuxt: v2.14.12
  • node: v14.15.3

I did run nuxt build command then,
when i run pm2-runtime start ecosystem.yml on docker, i get this error:

Error: No build files found in
/var/www/ui/ecosystem.config.yaml/.nuxt/dist/server.
Use either nuxt build or builder.build() or start nuxt in development mode.

how i can solve that?

Copy link
Member

Atinux commented Jan 27, 2021

Please give more informations, like what is your ecosystem.yml?

@Atinux Atinux added the pending-repro label Jan 27, 2021 — with Volta.net
@farshidrezaei
Copy link
Author

farshidrezaei commented Jan 28, 2021

@Atinux

ecosystem.config.yaml

apps:
      - name: App
        exec_mode: cluster
        instances: max
        script: ./node_modules/nuxt/bin/nuxt.js
        args: start

Copy link
Member

Atinux commented Jan 28, 2021

@farshidrezaei
Copy link
Author

@Atinux Everything is ok. but when i run pm2-runtime start ecosystem.yml , i get that error.

Copy link
Member

Atinux commented Jan 30, 2021

From what I understand, the path giving to start Nuxt is wrong, try to set in the options: args: starts .

@farshidrezaei
Copy link
Author

@Atinux Is there nuxt starts command?

everything is correct. if run nuxt start, it will work, but withpm2 start ecosystem.yaml` rerurn error.

Copy link
Member

Atinux commented Jan 30, 2021

Sorry I meant start .

It seems that the rootDir detected is not correct.

Try to set in your nuxt.config.js:

export default {
  rootDir: __dirname
}

@farshidrezaei
Copy link
Author

@Atinux It did not help. seam error.

@Atinux Atinux added the help-wanted label Jan 31, 2021 — with Volta.net
Copy link
Member

@farshidrezaei You seem to be using ecosystem.yaml and ecosystem.yml interchangeably. Would you confirm that you are using the correct filename consistently throughout all your commands/configuration?

@farshidrezaei
Copy link
Author

@farshidrezaei You seem to be using ecosystem.yaml and ecosystem.yml interchangeably. Would you confirm that you are using the correct filename consistently throughout all your commands/configuration?

yes. everything is correct.
finally i fix my problem with another way without pm2.
i run directly nuxt start. and set some other docker configs.

thanks a lot.

@TheSycamore
Copy link

I am experiencing the same problem.

node: v14.16.0
nuxt: 2.15.3
pm2: 4.5.5

Works fine:
pm2 start ecosystem.config.js

Doesn't work:
pm2-runtime start ecosystem.config.js

Error output:

✖ Nuxt Fatal Error
Error: No build files found in /var/www/ui/ecosystem.config.js/.nuxt/dist/server.
Use either `nuxt build` or `builder.build()` or start nuxt in development mode.

As you can see from above the path is incorrect:

Incorrect path:
/var/www/ui/ecosystem.config.js/.nuxt/dist/server

Intended path:
/var/www/ui/.nuxt/dist/server

My /var/www/ui/ecosystem.config.js file:

module.exports = {
  apps: [
    {
      name: 'ui',
      cwd: '/var/www/ui/',
      exec_mode: 'cluster',
      instances: 'max', // Or a number of instances
      script: './node_modules/nuxt/bin/nuxt.js',
      args: 'start',
      env: {
        NODE_ENV: "development",
      },
      env_production: {
        NODE_ENV: "production",
      }
    }
  ]
}

Multiple people are having this issue including myself:
Unitech/pm2#4576
#8704
https://github_com.jam.dev/nuxt/nuxt.js/issues/8723

@danielroe danielroe removed the pending-repro label Mar 27, 2021 — with Volta.net
Copy link
Member

Atinux commented Mar 27, 2021

Shall we re-open @danielroe ?

@danielroe danielroe reopened this Mar 27, 2021
@dmorais8
Copy link

Any updates? Im getting the same error trying to run a Nuxt app on Docker container with pm2-runtime.

@farshidrezaei
Copy link
Author

farshidrezaei commented Apr 17, 2021

@dmorais8
@TheSycamore

Don't use pm2 in docker. just run nuxt start and set restart: always in your container.

@melnikovdv
Copy link

I have the same issue, but without pm2. Just build Nuxt (2.15.4) as usual npm run build, but No build files found in /frontend/.nuxt/dist/server.

I'm using MacBook m1 and docker with --platform linux/amd64 if it can be useful. When I build without docker files .nuxt/dist/server are there.

@melnikovdv
Copy link

I'm sorry, I figured out what happened in my case.

For a docker build from node:lts-alphine it was a silent error that finished build successfully, but without .nuxt/dist/server and .nuxt/dist/clien files.

With a node:lts build failed with error 137, which is OutOfMemory in most cases. I increased default Docker settings with memory and cores and now everything is ok.

My bad. The only weird thing is that with node:lts-alphine docker build didn't show any error.

@Elainelele
Copy link

Elainelele commented May 7, 2021

I have the same issue. I modified the @nuxt/config/dist/config.js code can run success.
image
rootDir = path__default['default'].resolve(rootDir);
to
rootDir = process.cwd();
then rebuild and restart is OK~

@coheonsb
Copy link

coheonsb commented May 17, 2021

try first

pm2 list

@TheSycamore

"scripts": {
    "postinstall": "patch-package",
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "./node_modules/pm2/bin/pm2 save --force && ./node_modules/pm2/bin/pm2 list && ./node_modules/pm2/bin/pm2-runtime start ecosystem.config.js ",
    "server" : "nuxt start",
    "generate": "nuxt generate",
    "lint": "eslint --format ./node_modules/eslint-friendly-formatter --ext .js,.vue .",
    "lint:fix": "eslint --format ./node_modules/eslint-friendly-formatter --ext .js,.vue . --fix"
  },

https://www.python2.net/questions-1253548.htm

It`s works for me

@konstantp
Copy link

I need to run nuxt app inside docker container and it should start using pm2-runtime. Any updates on this issue?

@1peng
Copy link

1peng commented Jul 8, 2021

ecosystem.json or ecosystem. yml

args: "start -c /xxx/xxx/nuxt.config.js"

ecosystem.config.js

args: `start -c ${process.cwd()}/nuxt.config.js`,

nuxt.config.js

rootDir: process.cwd()
buildDir: process.cwd() + '/.nuxt/'

@galaxy-s10
Copy link

is no resolved,if use ecosystem.config.js,pm2-runtime start ecosystem.config.js is ok,but if use shell,pm2-runtime start './node_modules/nuxt/bin/nuxt.js' --name aaaa -i 1 -- start -c /Users/huangshuisheng/Desktop/hss/galaxy-s10/nuxt-blog-client/nuxt.config.js, is no work

@galaxy-s10
Copy link

没有解决,如果使用ecosystem.config.js,pm2-runtime start ecosystem.config.js可以,但是如果使用shell,pm2-runtime start './node_modules/nuxt/bin/nuxt.js' --name aaaa -i 1 -- start -c /Users/huangshuisheng/Desktop/hss/galaxy-s10/nuxt-blog-client/nuxt.config.js,是不行的

see: Unitech/pm2#4576

@galaxy-s10
Copy link

Although I don't know why, before executing pm2-runtime, run pm2 list or pm2 update first, and pm2-runtime will work normally without error:'xxxxxx/.nuxt/dist/server.', which is amazing

@galaxy-s10
Copy link

try first

pm2 list

@TheSycamore

"scripts": {
    "postinstall": "patch-package",
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "./node_modules/pm2/bin/pm2 save --force && ./node_modules/pm2/bin/pm2 list && ./node_modules/pm2/bin/pm2-runtime start ecosystem.config.js ",
    "server" : "nuxt start",
    "generate": "nuxt generate",
    "lint": "eslint --format ./node_modules/eslint-friendly-formatter --ext .js,.vue .",
    "lint:fix": "eslint --format ./node_modules/eslint-friendly-formatter --ext .js,.vue . --fix"
  },

https://www.python2.net/questions-1253548.htm

It`s works for me

Although I don't know why, before executing pm2-runtime, run pm2 list or pm2 update first, and pm2-runtime will work normally without error:'xxxxxx/.nuxt/dist/server.', which is amazing

@amartinez-forrester
Copy link

Could anyone provide the full ecosystem file + script that you are using to start the app using pm2? I am facing the same issue. I only see a few hacks without explaining the full solution.

@galaxy-s10
Copy link

谁能提供您使用 pm2 启动应用程序所使用的完整生态系统文件 + 脚本?我面临同样的问题。我只看到了一些 hack 而没有解释完整的解决方案。

my wechat:shuisheng9905,I may be able to help you remotely,or,Provide your github repo,i can pullrequest

@amartinez-forrester
Copy link

amartinez-forrester commented Mar 9, 2023

@galaxy-s10, I've realized that doesn't make any sense to use pm2 inside a docker container and we switched to the default "npm run start" way. Doing a pm2 update && pm2-runtime xxxx worked fine.

A few links related to docker vs pm2 and why you shouldnt use both of them:
https://stackoverflow.com/questions/51191378/what-is-the-point-of-using-pm2-and-docker-together
https://maximorlov.com/pm2-to-docker-automatic-restarts/
https://maximorlov.com/from-pm2-to-docker-cluster-mode/

@galaxy-s10
Copy link

@galaxy-s10,我意识到在 docker 容器中使用 pm2 没有任何意义,我们切换到默认的“npm run dev”方式。执行 pm2 update && pm2-runtime xxxx 工作正常。

一些与 docker vs pm2 相关的链接以及为什么不应该同时使用它们:https: //stackoverflow.com/questions/51191378/what-is-the-point-of-using-pm2-and-docker-together https: //maximorlov.com/pm2-to-docker-automatic-restarts/ https://maximorlov.com/from-pm2-to-docker-cluster-mode/

OK Thank you, but I think even if you don't use pm2 in the docker, you should also use npm run build&&npm run start, because the memory occupied by npm run dev is much larger than the npm run start executed after the build

@amartinez-forrester
Copy link

@galaxy-s10,我意识到在 docker 容器中使用 pm2 没有任何意义,我们切换到默认的“npm run dev”方式。执行 pm2 update && pm2-runtime xxxx 工作正常。
一些与 docker vs pm2 相关的链接以及为什么不应该同时使用它们:https: //stackoverflow.com/questions/51191378/what-is-the-point-of-using-pm2-and-docker-together https: //maximorlov.com/pm2-to-docker-automatic-restarts/ https://maximorlov.com/from-pm2-to-docker-cluster-mode/

OK Thank you, but I think even if you don't use pm2 in the docker, you should also use npm run build&&npm run start, because the memory occupied by npm run dev is much larger than the npm run start executed after the build

Oh, sorry. I used npm run start, I've just put the wrong command there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests