nuxt: Nuxt SSR deployment on docker with pm2 has error.

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?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (6 by maintainers)

Most upvoted comments

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/'

Shall we re-open @danielroe ?

@dmorais8 @TheSycamore

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

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~

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

@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.

@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/

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

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

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: https://github.com/Unitech/pm2/issues/4576 https://github.com/nuxt/nuxt.js/issues/8704 https://github_com.jam.dev/nuxt/nuxt.js/issues/8723

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